1

When I do an ls of either dir, their contents are very similar

/sys/class/block

$ 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

/sys/block/

$ 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

They both have numerous symlinks to the same place. The only difference I see is /sys/class/block/ has sda and sda1 through sda6 while /sys/block/ has only sda.

What is the main difference between /sys/block/ and /sys/class/block?

3

The latter exists for compatibility reasons, because sysfs originally had dedicated code for block devices, but later those became just another "class". See commit v2.6.24-158-gedfaa7c36574:

Driver core: convert block from raw kobjects to core devices

This moves the block devices to /sys/class/block. It will create a flat list of all block devices, with the disks and partitions in one directory. For compatibility /sys/block is created and contains symlinks to the disks.

(Found using tig blame drivers/base/class.c)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.