I’ve been wondering how to enable automounting of USB drives on my Raspberry Pi server. The sollution is pretty simple with udev on Arch Linux.
- Create a new file
/etc/udev/rules.d/automount.rules
- Fill this script:
ACTION=="add",KERNEL=="sda*", RUN+="/usr/bin/mount /dev/sda1 /mnt/disk-a" ACTION=="remove", KERNEL=="sda*", RUN+="/usr/bin/umount /mnt/disk-a"
- Run
udevadm control --reload-rules
to reload the rules. - Done!
Naturally you should modify the script to your needs. What this one does for me is that when sda1 is connected, it is mounted as /mnt/disk-a (and unmounted when removed). Adding more lines like this can be used to mount more / other drives.
One reply on “Linux udev USB automount script”
Hi,
thanks for this. Your tip works with just a couple of adjustments on Crux as well. Here is how I mounted my NTFS-formatted USB drive:
ACTION==”add”, KERNEL==”sdc*”, RUN+=”/bin/mount -t ntfs-3g /dev/sdc1 /mnt/corsair”
ACTION==”remove”, KERNEL==”sdc*”, RUN+=”/bin/umount /mnt/corsair”
Note the different path on Crux to the mount and umount commands.
Best regards, Gerard.