Linux udev USB automount script

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.

  1. Create a new file /etc/udev/rules.d/automount.rules
  2. 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"
  3. Run udevadm control --reload-rules to reload the rules.
  4. 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 comment on “Linux udev USB automount script
  1. Gerard Lally says:


    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.

Leave a Reply


