Skip to main content
4 of 5
deleted 79 characters in body
magva
  • 171
  • 1
  • 1
  • 4

mount is not executed when called by udev

I tried to create some udev rules to mount and unmount my USB flash drives; the rules for the moment are very simple:

ACTION=="add",KERNEL=="sd[b-z]",RUN+="/root/scripts/plug_flash_drive.sh %k" ACTION=="remove",KERNEL=="sd[b-z]",RUN+="/root/scripts/unplug_flash_drive.sh %k" 

plug_flash_drive.sh is also very simple:

device_name=$1 mount_options="umask=000,utf8" if [ ! -e "/media/$device_name" ]; then mkdir "/media/$device_name" fi sleep 1 /usr/bin/mount "/dev/$device_name" "/media/$device_name" -o "$mount_options" 

unplug_flash_drive.sh:

device_name=$1 umount "/dev/$device_name" rmdir "/media/$device_name" 

I have done some tests so I can ascertain that:

  • When plugged in, my flash drive is detected; a file is created in /dev
  • plug_flash_drive.sh is called by udev
  • the mkdir part of the script works
  • however, it seems that the "mount" part of the script is not executed, so my drive is not mounted
  • when I call my scripts on the command line, they perfectly work

Does anybody know why mount is not executed when called by udev?

magva
  • 171
  • 1
  • 1
  • 4