当我执行ls
任一目录时,它们的内容非常相似
/系统/类/块
$ ls /sys/class/block
dm-0 dm-3 loop1 loop4 loop7 ram10 ram13 ram2 ram5 ram8 sda1 sda4
dm-1 dm-4 loop2 loop5 ram0 ram11 ram14 ram3 ram6 ram9 sda2 sda5
dm-2 loop0 loop3 loop6 ram1 ram12 ram15 ram4 ram7 sda sda3 sda6
ls -lah /sys/class/block/
total 0
drwxr-xr-x 2 root root 0 Apr 23 16:08 .
drwxr-xr-x 52 root root 0 Apr 23 16:08 ..
lrwxrwxrwx 1 root root 0 Apr 23 16:08 dm-0 -> ../../devices/virtual/block/dm-0
lrwxrwxrwx 1 root root 0 Apr 23 16:08 dm-1 -> ../../devices/virtual/block/dm-1
lrwxrwxrwx 1 root root 0 Apr 23 16:08 dm-2 -> ../../devices/virtual/block/dm-2
lrwxrwxrwx 1 root root 0 Apr 23 16:08 dm-3 -> ../../devices/virtual/block/dm-3
lrwxrwxrwx 1 root root 0 Apr 23 16:08 dm-4 -> ../../devices/virtual/block/dm-4
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop0 -> ../../devices/virtual/block/loop0
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop1 -> ../../devices/virtual/block/loop1
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop2 -> ../../devices/virtual/block/loop2
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop3 -> ../../devices/virtual/block/loop3
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop4 -> ../../devices/virtual/block/loop4
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop5 -> ../../devices/virtual/block/loop5
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop6 -> ../../devices/virtual/block/loop6
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop7 -> ../../devices/virtual/block/loop7
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram0 -> ../../devices/virtual/block/ram0
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram1 -> ../../devices/virtual/block/ram1
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram10 -> ../../devices/virtual/block/ram10
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram11 -> ../../devices/virtual/block/ram11
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram12 -> ../../devices/virtual/block/ram12
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram13 -> ../../devices/virtual/block/ram13
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram14 -> ../../devices/virtual/block/ram14
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram15 -> ../../devices/virtual/block/ram15
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram2 -> ../../devices/virtual/block/ram2
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram3 -> ../../devices/virtual/block/ram3
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram4 -> ../../devices/virtual/block/ram4
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram5 -> ../../devices/virtual/block/ram5
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram6 -> ../../devices/virtual/block/ram6
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram7 -> ../../devices/virtual/block/ram7
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram8 -> ../../devices/virtual/block/ram8
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram9 -> ../../devices/virtual/block/ram9
lrwxrwxrwx 1 root root 0 Apr 23 16:08 sda -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
lrwxrwxrwx 1 root root 0 Apr 23 16:08 sda1 -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
lrwxrwxrwx 1 root root 0 Apr 23 16:08 sda2 -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda2
lrwxrwxrwx 1 root root 0 Apr 23 16:08 sda3 -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda3
lrwxrwxrwx 1 root root 0 Apr 23 16:08 sda4 -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda4
lrwxrwxrwx 1 root root 0 Apr 23 16:08 sda5 -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda5
lrwxrwxrwx 1 r
/系统/块/
$ ls /sys/block/
dm-0 dm-3 loop1 loop4 loop7 ram10 ram13 ram2 ram5 ram8
dm-1 dm-4 loop2 loop5 ram0 ram11 ram14 ram3 ram6 ram9
dm-2 loop0 loop3 loop6 ram1 ram12 ram15 ram4 ram7 sda
$ ls -lah /sys/block/
drwxr-xr-x 2 root root 0 Apr 23 16:08 .
dr-xr-xr-x 13 root root 0 Apr 23 16:08 ..
lrwxrwxrwx 1 root root 0 Apr 23 16:08 dm-0 -> ../devices/virtual/block/dm-0
lrwxrwxrwx 1 root root 0 Apr 23 16:08 dm-1 -> ../devices/virtual/block/dm-1
lrwxrwxrwx 1 root root 0 Apr 23 16:08 dm-2 -> ../devices/virtual/block/dm-2
lrwxrwxrwx 1 root root 0 Apr 23 16:08 dm-3 -> ../devices/virtual/block/dm-3
lrwxrwxrwx 1 root root 0 Apr 23 16:08 dm-4 -> ../devices/virtual/block/dm-4
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop0 -> ../devices/virtual/block/loop0
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop1 -> ../devices/virtual/block/loop1
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop2 -> ../devices/virtual/block/loop2
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop3 -> ../devices/virtual/block/loop3
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop4 -> ../devices/virtual/block/loop4
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop5 -> ../devices/virtual/block/loop5
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop6 -> ../devices/virtual/block/loop6
lrwxrwxrwx 1 root root 0 Apr 23 16:08 loop7 -> ../devices/virtual/block/loop7
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram0 -> ../devices/virtual/block/ram0
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram1 -> ../devices/virtual/block/ram1
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram10 -> ../devices/virtual/block/ram10
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram11 -> ../devices/virtual/block/ram11
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram12 -> ../devices/virtual/block/ram12
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram13 -> ../devices/virtual/block/ram13
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram14 -> ../devices/virtual/block/ram14
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram15 -> ../devices/virtual/block/ram15
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram2 -> ../devices/virtual/block/ram2
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram3 -> ../devices/virtual/block/ram3
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram4 -> ../devices/virtual/block/ram4
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram5 -> ../devices/virtual/block/ram5
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram6 -> ../devices/virtual/block/ram6
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram7 -> ../devices/virtual/block/ram7
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram8 -> ../devices/virtual/block/ram8
lrwxrwxrwx 1 root root 0 Apr 23 16:08 ram9 -> ../devices/virtual/block/ram9
lrwxrwxrwx 1 root root 0 Apr 23 16:08 sda -> ../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
它们都有许多指向同一位置的符号链接。我看到的唯一区别是/sys/class/block/
hassda
和sda1
through sda6
while /sys/block/
has only sda
。
/sys/block/
和 的主要区别是什么/sys/class/block
?
答案1
后者是出于兼容性原因而存在的,因为 sysfs 最初有专门用于块设备的代码,但后来这些代码变成了另一个“类”。请参阅提交v2.6.24-158-gedfaa7c36574
:
驱动核心:将块从原始 kobject 转换为核心设备
这会将块设备移至 /sys/class/block。它将创建所有块设备的平面列表,磁盘和分区位于一个目录中。为了兼容,创建了 /sys/block 并包含指向磁盘的符号链接。
(使用 找到tig blame drivers/base/class.c
)