Thursday, November 8, 2018

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.)

1 comment:

  1. I've recently experimented with 'lsblk --merge' and it's been a game-changer, especially for managing complex storage setups. The command's ability to consolidate information and present it in a comprehensible way is a time-saver. It's like a breath of fresh air in the tech world, much needed for efficiency. Kudos for highlighting its benefits! By the way, Anemia Dubai sounds intriguing. What's the connection here?

    ReplyDelete