Ubuntu – Trying to create UDEV rule to mount removable drive exfat partition

exfatmountudev

So I am trying to create a udev rule to automatically mount a drives exfat partition to /media/offsite. My goal is to automatically mount a drive to /media/offsite and then kick off a .sh script to copy files around. I have been reading many guides and have learned a lot, but I am still getting stuck. Many of the guides are very outdated and apply to USB drives where as I have a docked drive.

Just to see if a rule would trigger, I created this rule in /etc/udev/rules.d/80-external-disk.rules:

ACTION=="add", ENV{DEVTYPE}=="partition", ENV{ID_FS_UUID}=="5359-818E", RUN+="/bin/mount -t exfat -U $env{ID_FS_UUID}"

I reloaded rules, rebooted server, few other things, and it appeared the rule wasn't firing.

udevadm test $(udevadm info -q path -n /dev/sdb) 2>&1 | grep /etc/udev/rules.d

That only produces the following;

parse_file: reading '/etc/udev/rules.d/70-persistent-cd.rules' as rules file
parse_file: reading '/etc/udev/rules.d/70-persistent-net.rules' as rules file
parse_file: reading '/etc/udev/rules.d/80-external-disk.rules' as rules file

My thought is that the UUID belongs to the partition and not the drive. With the partition being an exfat, can UDEV even see that UUID?

Best Answer

  • mount is not allowed in the late releases of udev. Better to go with udisks if you are using Gnome/Unity or any other alternative for other DE.

    man udev

    RUN

    Note that running programs that access the network or mount/unmount filesystems is not allowed inside of udev rules, due to the default sandbox that is enforced on systemd-udevd.service.