This is a standard part of Linux auto mounting, so anything you find on Ubuntu administration applies. If you wanted to manually change an existing mount the “mount -o remount,rw…” can do the umount and mount in one command. Otherwise, you probably want to modify “/etc/fstab”. If you have an exact ID (e.g., UUID from lsblk) or an exact device (e.g., “/dev/mmcblk1p1”), then it shouldn’t be too difficult. Other more automatic setup may require changing a udev rule.
Beware any disk not mounted read-only has to be correctly umount’ed before removing.
In the following the UUID of a specific SD card is interchangeable with “/dev/mmcblk1p1” for SD card first partition…UUID will apply if it is a specifically formatted SD (per-specific-SD-card instructions), mmcblk1p1 will apply to any SD in the slot. The choice is whether you want all SD cards or a specific SD card to have this behavior. For example, if blkid shows this:
/dev/mmcblk1p1: UUID="4488e569-8a44-40f3-abf2-62f4f7d83250" TYPE="ext4"
…then the following “/etc/fstab” entry will force mount point to be “/custom” and allow even some insecure behavior (such as allowing suid root) if found during boot and to not complain if the SD card is not present (note “nouser” is restrictive and used because this will always be mounted without every user needing control; “async” increases performance but is one reason proper umount is needed when writable; nofail stops the mount from being mandatory; the “0 2” is for file system maintenance reasons):
UUID=4488e569-8a44-40f3-abf2-62f4f7d83250 /custom ext4 rw,suid,dev,exec,nouser,async,nofail 0 2
See: “man mount” and “man fstab” for more option info.
This is completely automatic only during boot. Note that you would not need to name any options to mount this card, the fstab entry would take care of that if you name the device or mount point covered in fstab. Once you “umount” you could just “mount /custom” and the next SD card would be mounted.
To get more automation you need to mess with udev. An entry in fstab with more automation would look something like this, where I think gvfs does something with udev:
/dev/mmcblk1p1 /custom auto comment=x-gvfs-show,noauto,rw,user 0 1
Important note if experimenting with fstab: If you have an invalid entry or an entry which is considered “mandatory mount”, then a failure could hang the system during boot. This shows up on serial console, but you probably won’t see it on regular console. Serial console does not respond to the instruction to skip the mount, you’ll need to blindly hit the ‘s’ key to skip that mount from the directly attached keyboard to continue boot. The “noauto” option is to tell init in bootup to not automatically mount this; the gvfs comment is to give nautilus control (nautilus does not run until after basic boot).