Advertisement
jpkotta

udev automount

May 26th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. # vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=udevrules:
  2. #
  3. # /etc/udev/rules.d/automount.rules
  4.  
  5. # start at sdb to ignore the system hard drive
  6. KERNEL!="sd[b-z]*", GOTO="automount_end"
  7. ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="automount_end"
  8.  
  9. # import some useful filesystem info as variables
  10. IMPORT{program}="/sbin/blkid -o udev -p %N"
  11.  
  12. # get the label if present, otherwise assign one based on device/partition
  13. ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
  14. ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"
  15.  
  16. # create the dir in /media and symlink it to /mnt
  17. ACTION=="add", RUN+="/bin/mkdir -p '/media/%E{dir_name}'"
  18.  
  19. # global mount options
  20. ACTION=="add", ENV{mount_options}="relatime"
  21. # filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat)
  22. ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=plugdev,dmask=007,fmask=117,utf8"
  23.  
  24. # automount ntfs filesystems using ntfs-3g driver
  25. ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"
  26. # automount all other filesystems
  27. ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"
  28.  
  29. # clean up after device removal
  30. ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'", RUN+="/bin/rmdir '/media/%E{dir_name}'"
  31.  
  32. # exit
  33. LABEL="automount_end"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement