The original idea comes from "dmsetup ls --tree", but lsblk(8) is better :-) It uses "holders" and "slaves" from /sys filesystem. This means that the util is usable without root permissions and it works for all types of block devices (dmsetup uses DM ioctls).
For example my laptop with dm-crypted $HOME and partitioned RAID0 (md8) on scsi_debug device (sdc):
$ lsblkYou can also list more details about devices. The next example is from scsi_debug device with 4KiB sectors and enabled alignment offset:
NAME MAJ:MIN RA SIZE RO MOUNTPOINT
sda 8:0 0 93.2G 0
├─sda1 8:1 0 102M 0 /mnt/test
├─sda2 8:2 0 1K 0
├─sda3 8:3 0 2.3G 0 [SWAP]
├─sda4 8:4 0 76.2G 0 /
├─sda5 8:5 0 10G 0
│ └─kzak-home (dm-0) 253:0 0 10G 0 /home/kzak
└─sda6 8:6 0 4.7G 0 /boot
sdc 8:32 0 500M 0
├─sdc1 8:33 0 250M 0
│ └─md8 9:8 0 498.9M 0
│ ├─md8p1 259:0 0 100M 0
│ ├─md8p2 259:1 0 100M 0
│ └─md8p3 259:2 0 297.9M 0
└─sdc2 8:34 0 249M 0
└─md8 9:8 0 498.9M 0
├─md8p1 259:0 0 100M 0
├─md8p2 259:1 0 100M 0
└─md8p3 259:2 0 297.9M 0
$ lsblk --topology /dev/sdblsblk(8) is also usable in script, for example:
NAME ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED
sdb 3584 4096 32768 4096 512 0 cfq
├─sdb1 0 4096 32768 4096 512 0 cfq
└─sdb2 0 4096 32768 4096 512 0 cfq
$ lsblk --nodeps --noheading --raw -o ALIGNMENT /dev/sdbreturns only alignment-offset for device sdb.
3584
Thanks to Milan Broz (from Red Hat) who is author of the original lsblk(8) prototype.
Nice tool! Output looks similar to "findmnt" (maybe findmnt should be renamed to lsmnt, to fit into all other ls* utils?).
ReplyDeleteAnyway, all your devices have readahead of 0? Shouldn't it be non-zero by default? On my typical system:
# blockdev --getra /dev/sda
1024
to zdzichuBG:
ReplyDeletehmm... RA in lsblk means "removable" (0/1), maybe the column should be renamed, any suggestion?
Why not just RM? It's well-known abbreviation for "remove" and I believe its meaning will be pretty obvious.
ReplyDeleteIs it possible to sort the folders by their size in the human readable format?
ReplyDeleteexample:
sdc2 8:34 0 249M 0
└─md8 9:8 0 498.9M 0
├─md8p1 259:0 0 100M 0
├─md8p2 259:1 0 100M 0
└─md8p3 259:2 0 297.9M 0
would look like this:
sdc2 8:34 0 249M 0
└─md8 9:8 0 498.9M 0
├─md8p3 259:2 0 297.9M 0
├─md8p1 259:0 0 100M 0
└─md8p2 259:1 0 100M 0
To Przemoc: yes, RM is good idea. Fixed.
ReplyDeleteTo Anonymous: good idea -- not implemented yet, added to TODO file.
Thanks for your feedback.
Hello what theme are you using for this?
ReplyDeleteavh-p3200bt
Very cool, and very useful.
ReplyDeleteVery nice. Too bad it's not in the current (Nov 2012) Debian stable (and findmnt isn't either).
ReplyDelete