是什么原因导致/ dev / disk / by-label被填充?


14

我注意到Linux发行版通常有一个/ dev / disk / by-label目录,但并非总是如此(例如,CirrOS Linux测试映像没有该目录)。

在Linux系统上,正确填充/ dev / disk / by-label目录有什么要求?


我不知道这一点,但我想udev可能与这类事情有关。

Answers:


10

在大多数现代Linux系统上,/devudev 几乎将所有内容放在了那里。

在我的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/如果您想为设备命名,更改权限等,则可以放置其他规则文件。例如,这里有一个填充和设置a上的权限的文件/dev/disk/for-asm


0

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:                      


1
实际上,这全都是udev,与udisk无关。
derobert
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.