我注意到 Linux 发行版通常有一个 /dev/disk/by-label 目录,但情况并非总是如此(例如,西罗操作系统Linux 测试映像没有)。
Linux 系统上需要什么才能正确填充 /dev/disk/by-label 目录?
答案1
在大多数现代 Linux 系统上,几乎所有内容/dev
都是由 udev 放置在那里的。
在我的 Debian 机器上,/dev/disk/by-label
来自以下几个文件/lib/udev/rules.d
例如,以下是来自 的规则60-persistent-storage.rules
:
ENV{ID_FS_LABEL_ENC}=="?*", ENV{ID_FS_USAGE}=="filesystem|other", \
SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}"
前面几行是ID_FS_LABEL_ENC
来自哪里:
# probe filesystem metadata of disks
KERNEL!="sr*", IMPORT{program}="/sbin/blkid -o udev -p $tempnode"
您可以blkid
自己运行以查看传递给 udev 的数据:
root@Zia:~# /sbin/blkid -o udev -p /dev/sda2
ID_FS_SEC_TYPE=msdos
ID_FS_LABEL=xfer1
ID_FS_LABEL_ENC=xfer1
ID_FS_UUID=B140-C934
ID_FS_UUID_ENC=B140-C934
ID_FS_VERSION=FAT16
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_PART_ENTRY_SCHEME=dos
ID_PART_ENTRY_TYPE=0xc
ID_PART_ENTRY_NUMBER=2
ID_PART_ENTRY_OFFSET=257040
ID_PART_ENTRY_SIZE=257040
ID_PART_ENTRY_DISK=8:0
确实:
root@Zia:~# ls -l /dev/disk/by-label/xfer1
lrwxrwxrwx 1 root root 10 Nov 19 10:02 /dev/disk/by-label/xfer1 -> ../../sda2
如果您想为设备创建其他名称、更改权限等,您可以放入其他规则文件。/etc/udev/rules.d/
例如,这里我们有一个用于填充和设置/dev/disk/for-asm
.
答案2
udisks-daemon
可能正在这样做(尽管 HAL 或 DBUS 也可以)。如果你愿意的话,你可以看着它发生。打开终端并运行:
udisks --monitor-detail
然后插入驱动器。你会得到类似的东西:
job-changed: /org/freedesktop/UDisks/devices/sdb1
job underway: FilesystemMount, initiated by uid 1000
changed: /org/freedesktop/UDisks/devices/sdb1
Showing information for /org/freedesktop/UDisks/devices/sdb1
native-path: /sys/devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4:1.0/host3/target3:0:0/3:0:0:0/block/sdb/sdb1
device: 8:17
device-file: /dev/sdb1
presentation: /dev/sdb1
by-id: /dev/disk/by-id/usb-SanDisk_Cruzer_20054858820EEB607D7D-0:0-part1
by-id: /dev/disk/by-uuid/D033-D063
by-path: /dev/disk/by-path/pci-0000:00:1a.7-usb-0:4:1.0-scsi-0:0:0:0-part1
detected at: Wed 21 Nov 2012 07:45:47 AM EST
system internal: 0
removable: 0
has media: 1 (detected at Wed 21 Nov 2012 07:45:47 AM EST)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 1
mount paths: /media/CRUZER
mounted by uid: 1000
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
size: 8000094208
block size: 512
job underway: no
usage: filesystem
type: vfat
version: FAT32
uuid: D033-D063
label: CRUZER
partition:
part of: /org/freedesktop/UDisks/devices/sdb
scheme: mbr
number: 1
type: 0x0b
flags:
offset: 16384
alignment offset: 0
size: 8000094208
label:
uuid: