it is not clear which is the current 'officially' supported approach.
Officially supported by whom? If e.g. GNOME includes automount functionality based on udisks, you can be sure it's officially supported by GNOME themselves.
I am more interested in the second (i.e. whatever USB storage device), since for the first I can just add the entries to /etc/fstab
.
There's no "standard way" for doing that. At best, the majority of existing systems have settled on adding automation on top of udisks2
. On its own, udisks doesn't automount anything at all – but it's the "backend" used by many graphical desktop environments (at least both GNOME and Xfce use it; I'm only 80% sure about KDE and Enlightenment).
(So your option 3 would be "udisks2 + automount by udiskie", and option 4 would be "udisks2 + automount by desktop environment".)
Regarding udev rules: whether it's about mounting filesystems or starting services, the short answer is "don't do it" (for various reasons); but the long answer is: "don't do it directly, but you can ask init to do it". So it wouldn't be horrible to run systemd-mount
from an udev rule, which then just passes the mount request to init just like a .mount unit would...
However, expect this to trigger a systemd bug/wart/misfeature: as udev reports the device to be ready only after processing the rules, you could end up with init automatically unmounting the disk because it thinks the device isn't there yet.
Instead, udevil would work better, since it doesn't run anything via rules but only reacts to "device ready" events emitted by udev.
fstab entries are oriented towards static devices. However, they can be sort-of abused for miscellaneous USB sticks by using /dev/disk/by-path/...
, which corresponds to the physical path of a device (e.g. PCI slot 3, USB port 1, partition 1...) This way you can write a fstab entry which matches any disk plugged in to the same USB port.
The autofs kernel automounter is, similarly to udisks, just the backend upon which various automounts can be implemented by userspace. Once an autofs mount is set up, all attempts to access it are reported to the corresponding daemon. The most common implementations are the traditional (maps-based) autofs
, and recently systemd
with the .automount units.
So the "dynamic" USB device logic would still have to be implemented in userspace, and either way it's more work than just using udisks.
With plain systemd, your only option is to build on top of the above fstab "by-path" hack. Once you write a fstab entry for the desired USB port, you can mark it with x-systemd.automount,x-systemd.idle-timeout=300
to use the autofs automounter. (Or, of course, create standalone .mount + .automount units for the same result.)
If you want to dynamically generate automounts for all USB disks on all ports, systemd cannot do that without third-party scripts.
I don't know whether autofsd
can do what you want, but I remember that it supports some kinds of dynamic maps (for user home directories). Perhaps using the program
map-type (and a script which enumerates all connected disks) would work.
Best Answer
I found the solution here. I used the Synaptic Package Manager to uninstall the udisks utility and install the udisks2 utility. I rebooted the computer, and my problem was solved! It seems like maybe my in-place upgrade between Linux Mint versions didn't upgrade the udisk utility; maybe the newer versions are not compatible with udisks.