我有 3 个驱动器,用于在我的系统上进行存储。这是它们的安装点/etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda1 during installation
UUID=f3cfbb3a-5014-4e0a-9b9d-ef4fde8f4031 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda6 during installation
UUID=9322c5b4-9157-49ab-b890-0b8d909b416f none swap sw 0 0
#store1
UUID=a2d57cda-515c-43e1-8d93-4f0d8714b713 /media/store1 ext4 errors=remount-ro 0 1
#store2
UUID=4f6bc0a9-5c9f-413b-9f8b-dc95e5a9462b /media/store2 ext4 errors=remount-ro 0 1
#store3
UUID=bb214693-06bc-412f-a7f9-b60bf7618fc5 /media/store3 ext4 errors=remount-ro 0 1
由于某种原因,Ubuntu 再次自动挂载驱动器作为usbhd-*
命名约定。
/dev/sda5 on /media/store1 type ext4 (rw,errors=remount-ro)
/dev/sdb3 on /media/store2 type ext4 (rw,errors=remount-ro)
/dev/sdc1 on /media/store3 type ext4 (rw,errors=remount-ro)
/dev/sdc1 on /media/usbhd-sdc1 type ext4 (rw,relatime)
/dev/sdb1 on /media/usbhd-sdb1 type ext4 (rw,relatime)
/dev/sdb3 on /media/usbhd-sdb3 type ext4 (rw,relatime)
我的/etc/udev/rules.d/media-by-label-auto-mount.rules
包含
# Start at sdb to avoid system harddrive.
KERNEL!="sd[b-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}="usbhd-%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"
# Mount the device
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"
我认为这意味着它忽略了/dev/sd*
驱动器。
关于如何阻止这种情况发生有什么想法吗?
答案1
如果我正确地阅读了这条规则:
# Start at sdb to avoid system harddrive.
KERNEL!="sd[b-z][0-9]", GOTO="media_by_label_auto_mount_end"
它是说,如果设备不等于 ( !=
) sdb0
、sdb1
等,则转到标签"media_by_label_auto_mount_end"
。
所以它对我来说似乎工作正常。
如果你这样做怎么办?:
KERNEL="sd[b-z][0-9]", GOTO="media_by_label_auto_mount_end"
或者,您可以在现有规则之前放置一条规则KERNEL!=
,该规则与您想要的任何sd*
驱动器相匹配,并将其转到标签后面的标签"media_by_label_auto_mount_end"
。从那时起,您可以创建任何您想要的规则,如下所示:
ENV{ID_FS_LABEL}=="", ENV{dir_name}="myusbhd-%k"