树莓派USB存储设备自动挂载

输入命令:
sudo nano /etc/udev/rules.d/10-usbstorage.rules

复制粘贴这个脚本到编辑窗口

KERNEL!="sd*", GOTO="media_by_label_auto_mount_end" 
SUBSYSTEM!="block",GOTO="media_by_label_auto_mount_end"
IMPORT{program}="/sbin/blkid -o udev -p %N" 
ENV{ID_FS_TYPE}=="", GOTO="media_by_label_auto_mount_end"
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}" 
ENV{ID_FS_LABEL}=="", ENV{dir_name}="Untitled-%k" 
ACTION=="add", ENV{mount_options}="relatime,sync" 
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", ENV{mount_options}="iocharset=utf8,umask=000" 
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", ENV{mount_options}="iocharset=utf8,umask=000" 
ACTION=="add", RUN+="/bin/mkdir -p /home/pi/usb/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /home/pi/usb/%E{dir_name}" 

ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /home/pi/usb/%E{dir_name}", RUN+="/bin/rmdir /home/pi/usb/%E{dir_name}" 
LABEL="media_by_label_auto_mount_end"

保存退出,再次插入usb存储设备会自动挂载到/media目录下面的目录 并且支持utf8格式的中文文件名。

你可能感兴趣的:(树莓派USB存储设备自动挂载)