Karel Zak: lsblk –merge


For uti-linux version v2.34 (next spring) I’m working on new lsblk. The goal is keep all devices as data structs in memory to have ability to modify or reorder the tree.

Now lsblk blindly follows slaves/holders links in /sys and in case of RAIDs or multi-path devices the output contains duplicate lines.

The new version will provide de-duplication (lsblk –dedup WWN) to completely remove unnecessary lines from output.

The another feature is possibility to use libsmartcols to specify group of lines and define children for the group. This allows to describe M:N relationships by chart without duplicate lines in output.

See the next example with one multi-path device and one RAID device.

$ lsblk --merge
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 223.6G 0 disk
├─sda1 8:1 0 200M 0 part /boot/efi
├─sda2 8:2 0 200M 0 part /boot
├─sda3 8:3 0 130.3G 0 part
├─sda4 8:4 0 50G 0 part /
┌┈┄┄▶ └─sda5 8:5 0 42.9G 0 part
┆ sdb 8:16 0 74.5G 0 disk
┆ └─sdb1 8:17 0 74.5G 0 part /home/archive
┆ ┌┈▶ sdc 8:32 0 100M 0 disk
┆ ├┈▶ sdd 8:48 0 100M 0 disk
┆ ├┈▶ sde 8:64 0 100M 0 disk
┆ └┬▶ sdf 8:80 0 100M 0 disk
┆ └┈┄mpatha 253:0 0 100M 0 mpath
┆ ├─mpatha1 253:1 0 50M 0 part
┆ └─mpatha2 253:2 0 49M 0 part
┆ nvme0n1 259:0 0 223.6G 0 disk
┆ ├─nvme0n1p1 259:1 0 7.8G 0 part
┆ ├─nvme0n1p2 259:2 0 200G 0 part /home
└┬┄┄▶ └─nvme0n1p3 259:3 0 15.8G 0 part
└┄┄┈┄md0 9:0 0 15.8G 0 raid1
├─md0p1 259:4 0 100M 0 md
└─md0p2 259:5 0 15.7G 0 md

The original lsblk output:

 
NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda 8:0 0 223.6G 0 disk
├─sda1 8:1 0 200M 0 part /boot/efi
├─sda2 8:2 0 200M 0 part /boot
├─sda3 8:3 0 130.3G 0 part
├─sda4 8:4 0 50G 0 part /
└─sda5 8:5 0 42.9G 0 part
└─md0 9:0 0 15.8G 0 raid1
├─md0p1 259:4 0 100M 0 md
└─md0p2 259:5 0 15.7G 0 md
sdb 8:16 0 74.5G 0 disk
└─sdb1 8:17 0 74.5G 0 part /home/archive
sdc 8:32 0 100M 0 disk
└─mpatha 253:0 0 100M 0 mpath
├─mpatha1 253:1 0 50M 0 part
└─mpatha2 253:2 0 49M 0 part
sdd 8:48 0 100M 0 disk
└─mpatha 253:0 0 100M 0 mpath
├─mpatha1 253:1 0 50M 0 part
└─mpatha2 253:2 0 49M 0 part
sde 8:64 0 100M 0 disk
└─mpatha 253:0 0 100M 0 mpath
├─mpatha1 253:1 0 50M 0 part
└─mpatha2 253:2 0 49M 0 part
sdf 8:80 0 100M 0 disk
└─mpatha 253:0 0 100M 0 mpath
├─mpatha1 253:1 0 50M 0 part
└─mpatha2 253:2 0 49M 0 part
nvme0n1 259:0 0 223.6G 0 disk
├─nvme0n1p1 259:1 0 7.8G 0 part
├─nvme0n1p2 259:2 0 200G 0 part /home
└─nvme0n1p3 259:3 0 15.8G 0 part
└─md0 9:0 0 15.8G 0 raid1
├─md0p1 259:4 0 100M 0 md
└─md0p2 259:5 0 15.7G 0 md

The code is still not ready to merge to the master branch and some cosmetic changes are expected, but the idea is obvious I guess. (If you want to play with it see topic/lsblk branch in util-linux repository.)


Source From: fedoraplanet.org.
Original article title: Karel Zak: lsblk –merge.
This full article can be read at: Karel Zak: lsblk –merge.

Advertisement


Random Article You May Like

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*