With every new release the way to automount USB drives in Linux seems to change (fortunately I'm using Debian, so I'm only losing a few days on this every 2 years). We used to have usbmount, udisks, udisks2, udisks-glue, pmount, custom udev rules, and I'm probably forgetting many more. (A quick look shows that at least a thing named afuse
seems to exist, but is not documented too well). None of these work anymore (for me at least).
What is the "current" way to automount USB drives in Debian? I used the following udev
rule, but since updating from stretch to buster this stopped working:
SUBSYSTEM=="usb", DRIVERS=="usb-storage", ACTION=="add", \
RUN+="mkdir /media/usb%n; mount -o gid=plugdev,umask=002,fmask=111,users /dev/%k%n /media/usb%n"
Also: what is the stable solution to do this, that will reliably work even after updating to a new release, that I probably missed?
Best Answer
You can create a
systemd.mount
andsystemd.automount
unit files. Here is an example:To mount
/dev/sdb1
under/mnt/moutpoint
, create amnt-mountpoint.automount
file:Note: The name of the unit file should be
dir-sub-dir.mount
extracted from the mount point/dir/sub-dir
(if you need to mount the device under/media
the name will bemedia-mountpoint.mount
)Then paste the following lines:
Use
blkid
to replace theUUID_here
with the uuid of/dev/sdb1
.Create the
mnt-mountpoint.automount
file:With the following lines:
Attach your USB then enable and start the units: