I used to do auto-mounting with udev like this:

# cat /etc/udev/rules.d/10-aaa.rules
KERNEL=="sda1", SUBSYSTEM=="block", RUN+="/etc/mymount.sh"

# cat /etc/mymount.sh
if [ "$ACTION" = "add" ]; then
    # Do some stuff
    mount /dev/sda1
elif [ "$ACTION" = "remove" ]; then
    # Do some other stuff
    umount /mnt/usba

# cat /etc/fstab | grep sda1
/dev/sda1  /mnt/usba  ext4  auto,rw,noatime,user  0  0

However I noticed that the letter for my drive may change, so I changed the fstab entry to this

PARTUUID=12345678-01  /mnt/usba  ext4  auto,rw,noatime,user  0  0

But it's no longer working because /dev/sda* is permantly attached (another drive) and I can't simply change the udev rule to sdb. How can I configure my udev rule so that it gets mounted correctly?

  • udevadm info --query=all -a --name sdXy For sdXy take the name of the devicenode. – user192526 Jul 12 '17 at 15:09
  • @Bahamut What is the device node? Like /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1 ? – iBug Jul 12 '17 at 15:43
  • No, like /dev/sdb1. – user192526 Jul 12 '17 at 15:46
  • @Bahamut But that changes every time I plug the drive in. – iBug Jul 16 '17 at 18:18
  • tail -f /var/log/syslog plug the hd in and you can see how it is recognize. then you can use udevadm and show it. – user192526 Jul 25 '17 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.