I have the following file of rules in /etc/udev/rules.d/

KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"  
# Import FS infos  
IMPORT{program}="/sbin/blkid -o udev -p %N"  
# Get a label if present, otherwise specify one  
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"  
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"  
# Global mount options  
ACTION=="add", ENV{mount_options}="relatime"  
# Filesystem-specific mount options  
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"  
# Mount the device  
ACTION=="add", RUN+="/bin/mkdir -p /media/dir", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/dir"  
# Clean up after removal  
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/dir", RUN+="/bin/rmdir /media/dir"  
# Exit  

The problem is that all the time I plug in the USB I have a message like that the USB is already mounted (/dev/sdb already mounted in /media/dir) and at unmount the user has no rights to unmount the USB. Also the normal user has no write permissions on the USB.

What can I change to be able to fix these issues?

Thank you.

  • Try: sudo rm -r /media/* without any USB-sticks. – Sergey Shitov Aug 4 '15 at 10:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.