====== udev - Auto Mount USB ====== 1. 在 /etc/udev/rules.d 下新增 udev 規則, 如 "11-media-by-label-auto-mount.rules" 2. 內容如下: KERNEL!="sd[a-z][0-9]", 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}="USB-%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" ACTION=="add", ENV{ID_FS_TYPE}=="vfat", ENV{mount_options}="-o relatime,utf8" ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", ENV{mount_options}="-t ufsd -o force" # Mount the device #ACTION=="add", RUN+="/media/ttt.sh add %k %E{dir_name} %E{ID_FS_TYPE}" ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount $env{mount_options} /dev/%k /media/%E{dir_name}" #ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}" # Clean up after removal ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}" # Exit LABEL="media_by_label_auto_mount_end" 3. That all~