Thursday, December 16, 2010

lsblk(8)

lsblk(8) is a new util that will be available in util-linux-2.19 (coming soon;-). The util lists all block devices as a tree. This output is very useful on machines with complicated storage setup (e.g. RAID, dm-crypt, ...). It's so useful that we'll probably backport lsblk(8) to RHEL-6 to make life easier for people who need to debug their systems.

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):
$ lsblk
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
You can also list more details about devices. The next example is from scsi_debug device with 4KiB sectors and enabled alignment offset:
$ lsblk --topology /dev/sdb
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(8) is also usable in script, for example:
$ lsblk --nodeps --noheading --raw -o ALIGNMENT /dev/sdb
3584
returns only alignment-offset for device sdb.

Thanks to Milan Broz (from Red Hat) who is author of the original lsblk(8) prototype.

8 comments:

  1. Nice tool! Output looks similar to "findmnt" (maybe findmnt should be renamed to lsmnt, to fit into all other ls* utils?).
    Anyway, all your devices have readahead of 0? Shouldn't it be non-zero by default? On my typical system:

    # blockdev --getra /dev/sda
    1024

    ReplyDelete
  2. to zdzichuBG:

    hmm... RA in lsblk means "removable" (0/1), maybe the column should be renamed, any suggestion?

    ReplyDelete
  3. Why not just RM? It's well-known abbreviation for "remove" and I believe its meaning will be pretty obvious.

    ReplyDelete
  4. Is it possible to sort the folders by their size in the human readable format?
    example:

    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

    ReplyDelete
  5. To Przemoc: yes, RM is good idea. Fixed.

    To Anonymous: good idea -- not implemented yet, added to TODO file.

    Thanks for your feedback.

    ReplyDelete
  6. Hello what theme are you using for this?


    avh-p3200bt

    ReplyDelete
  7. Very nice. Too bad it's not in the current (Nov 2012) Debian stable (and findmnt isn't either).

    ReplyDelete