Linux USB 设备自动挂载rules

/etc/udev/rules.d

添加文件

10-automount.rules
KERNEL!="sd[a-z]?", GOTO="automount_exit"
ACTION=="add", SUBSYSTEM=="block", RUN+="/bin/mkdir /media/%E{ID_FS_LABEL}-%E{ID_FS_UUID}", RUN+="/bin/mount -o uid=1000,user,codepage=936,utf8 $root/%k /media/%E{ID_FS_LABEL}-%E{ID_FS_UUID}"
ACTION=="remove", SUBSYSTEM=="block", RUN+="/bin/umount /media/%E{ID_FS_LABEL}-%E{ID_FS_UUID}", RUN+="/bin/rmdir /media/%E{ID_FS_LABEL}-%E{ID_FS_UUID}"
LABEL="automount_exit"

这时候,插上设备时会自动在

/media

创建文件夹挂载,移除设备时文件夹会自动删除

如果文章对你有帮助, 你可以: 请我喝可乐

Leave a Comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.