Approaches to auto-mounting devices in Linux keep changing, and googling returns quite a few solutions with various degrees of applicability for modern systemd-based boxes.
The following approaches seem to exist:
/etc/fstabto add per-drive mounts by UUID/label/device.
udevrules (apparently 'raw rules' might conflict with existing systemd policies)
- udisks2 running as a systemd service or via udiskie
- automounting provided by the desktop environments, i.e. on XFCE via
thunar-volmanpackages, or the
nautilusautomount in Gnome with the
gnome-volume-managerpackage (apparently they rely on udisks).
- autofs kernel automounter
- systemd automounting, example of usage: automount-usb
The choices can be overwhelming and it is not clear which is the current recommended approach. Moreover, it seems that different auto-mounting subsystems can conflict which each other leading to situations when a partition is mounted by one tool and then in a matter of seconds is automatically unmounted by another tool.
For systems with a desktop environment, it is straightforward since most of them handle USB-mounting automatically, so no extra action is necessary apart from enabling the automounting option in settings.
What would be the current approach for a headless system which mostly operates in text-mode?
After fiddling with all the options I found
usbmount to (almost) just work after I edited
/lib/systemd/system/systemd-udevd.service and changed
MountFlags=shared as described in this issue. No need to manually add any UUIDs or labels to any config files. The downside is that it creates the mount points under
/media/usbN which is not perfect, so I have switched to
automount-usb which was surprisingly easy to set up (just ran the
configure.sh script) and which creates mount folders like
/media/<device>_<disk_label> e.g. like
- Automatically mount external drives to /media/LABEL on boot without a user logged in?
Auto-Samba mounting: There is also a fork of automount-usb which automatically adds the attached USB drives as samba read-write mount points.