$ cat /proc/partitions
major minor #blocks name
8 0 976762584 sda
8 1 99998720 sda1
8 2 1 sda2
8 3 103561216 sda3
8 4 291514368 sda4
8 5 1998848 sda5
8 16 31506432 sdb
8 17 31505439 sdb1
I want to differentiate between physical disks (/dev/sda
) and logical disks (/dev/sda1
) from /proc/partitions
output.
- One easy way I see is to check with some regex pattern whether it ends with integer or not
- As I see the output on my machine
sda
has least minor value than allsdaN
entries - check for existence of
/sys/block/[NAME]
So I'll try to read/sys/block/sdaN
directories (which will fail) and/sys/block/sda
(which will succeed)
I don't know which one is reliable and Is there any other ways ?
Also how can I reliably make a tree structure like sda : {sda1, sda2, sda3, sda4, sda4}, sdb : {sdb1}
- just by its name
- by minor numbers
- again look into
/sys/block
- by position (Is it confirmed that sda1 will always come after sda ? e.g. would a logical partition entry always come after the physical disk entry ?)