Debian: Automount based on UUID on plugin

automountingdebianusb

I've got an ext4 pen drive whose UUID is bb7522af-2bda-4416-bcca-a076a1cf63a3.

I want to be able to connect it after boot and mount it to /home/Shared/Vaderive (All-user shared).

Is possible directly from GUI or something like usbmount or autofs?

uname -a:

Linux HOSTNAME 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 GNU/Linux

Best Answer

Edit your fstab as follows:

UUID=bb7522af-2bda-4416-bcca-a076a1cf63a3 /home/Shared/Vaderive auto defaults,noauto 0 0

Create udev rules under /lib/udev/rules.d to mount/unmount your device e,g:

nano /lib/udev/rules.d/automount.rules

With the following contents;

ACTION=="add", ENV{ID_FS_UUID_ENC}=="bb7522af-2bda-4416-bcca-a076a1cf63a3", RUN+="/bin/mount /dev/%k"
ACTION=="remove", ENV{ID_FS_UUID_ENC}=="bb7522af-2bda-4416-bcca-a076a1cf63a3", RUN+="/bin/umount /dev/%k"

Run udevadm control --reload-rules then check your files.

Related Question