udev实现自动挂载USB

环境debian testing+xfce12

解决依赖时不小心将gvfs,libusb2等删除掉了,重新安装后usb不能自动挂载。在/etc/udev/rules.d/中添加udev规则后解决:

参考: http://unix.stackexchange.com/questions/24731/automounting-usb-sticks-on-debian

 

#11-media-by-label-auto-mount.rules

 1 KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"
 2 
 3 # Import FS infos
 4 IMPORT{program}="/sbin/blkid -o udev -p %N"
 5 
 6 # Get a label if present, otherwise specify one
 7 ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
 8 ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"
 9 
10 # Global mount options
11 ACTION=="add", ENV{mount_options}="relatime"
12 # Filesystem-specific mount options
13 ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"
14 
15 # Mount the device
16 ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"
17 
18 # Clean up after removal
19 ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
20 
21 # Exit
22 LABEL="media_by_label_auto_mount_end"

 

书写规则参见:http://reactivated.net/writing_udev_rules.html

 

posted on 2014-08-27 22:42  子墨sky  阅读(2080)  评论(0编辑  收藏  举报

导航