Sample Header Ad - 728x90

How can I use lsblk to display all devices except my root/main "sda" device where my root filesystem is "/"?

3 votes
2 answers
373 views
I use LUKS (so my system is encrypted) and LVM. I don’t want sda displayed because that’s where my root filesystem lives, and it’s my root device. The solution should also work for systems without LUKS or LVM, meaning it must handle all scenarios. I'm on a Debian 12.x and I want to display all main devices in a one row command, if possible, ***except my root device***, regardless of whether it's an LVM, LUKS or not, etc. The command should be flexible, and I don’t want to use fixed specifications *--vg-root, etc., if possible. > **@bertieb comment:** From the added output, it seems the root mountpoint is in a volume group in an encrypted volume on the device is presenting itself as sda -- OP wants that entire device and all associated block 'devices' elided ? i.e. remove root vg AND swap, crypt, containing partition (sda3) plus other partitions, and finally the device (sda) And that should be my result, ***so all main devices without*** sda because that’s my root device where my root filesystem is /, and without me having to specify details, so I can use it on other **devices/systems** as well, whether LVM, LUKS, etc., without needing to know what root is called, or what the UUID is, etc. I don't want to see the partitions too, only the main devices without root device, like in this command lsblk -d -o NAME,SIZE --sort SIZE. This is the output I need: - No sda (since it's the root device containing my root filesystem /) - Only main devices displayed (regardless of how many exist) - No partitions included from the other devices ##### RESULT I NEED :
NAME     SIZE
nvme0n1  238.5G
**My Setup:**
$ lsblk -d -o NAME,SIZE --sort SIZE
NAME      SIZE
sda      57,3G
nvme0n1 238,5G
$ lsblk -fs -o NAME
# ROOT DEVICE
sda1
`-sda
sda2
`-sda
desktop--vg-root
`-sdb3_crypt
  `-sda3
    `-sda
...
...
$ lsblk
NAME                 MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
sda                    8:0    1  57,3G  0 disk  
├─sda1                 8:1    1   512M  0 part  /boot/efi
├─sda2                 8:2    1   488M  0 part  /boot
└─sda3                 8:3    1  56,3G  0 part  
  └─sdb3_crypt       254:0    0  56,3G  0 crypt 
    ├─desktop--vg-root   254:1    0  55,3G  0 lvm   /
    └─desktop--vg-swap_1 254:2    0   980M  0 lvm   [SWAP]
nvme0n1              259:0    0 238,5G  0 disk  
└─nvme0n1p1          259:1    0 238,5G  0 part  /user/backup
I don't want that, for example /dev/mapper/desktop--vg-root,sdb3_crypt, sda3 no sda. But rather this here from the example sda, this is the root device, so I don't need this device in the output. #### MY DEVICES, MY SETUP:
NAME           SIZE      
sda            57.3G     
|-sda1         512M      
|-sda2         488M      
`-sda3         56.3G     
`-sdb3_crypt   56.3G     
`-desktop--vg-swap_1980M      
nvme0n1        238.5G    
`-nvme0n1p1    238.5G
**RESULT I NEED:**
NAME     SIZE
nvme0n1  238.5G
##### System setup Debian, lsblk and other information:
Operating System: Debian GNU/Linux 12 (bookworm)  
Kernel: Linux 6.1.0-22-amd64
Architecture: x86-64
lsblk from util-linux 2.38.1
$ apt-get install --only-upgrade util-linux

util-linux is already the newest version (2.38.1-5+deb12u3)
##### From @terdon RESULT:
(){ lsblk -o NAME,SIZE,MOUNTPOINT | awk '$NF!="/"{printf "%-15s%-10s\n", $1,$2}'; }
NAME           SIZE      
sda            57.3G     
|-sda1         512M      
|-sda2         488M      
`-sda3         56.3G     
`-sdb3_crypt   56.3G     
`-desktop--vg-swap_1980M      
nvme0n1        238.5G    
`-nvme0n1p1    238.5G
$ lsblk -o NAME,SIZE,MOUNTPOINT
NAME                   SIZE MOUNTPOINT
sda                   57.3G 
|-sda1                 512M /boot/efi
|-sda2                 488M /boot
`-sda3                56.3G 
  `-sdb3_crypt        56.3G 
    |-desktop--vg-root    55.3G /
    `-desktop--vg-swap_1  980M [SWAP]
nvme0n1              238.5G
$ lsblk -o NAME,SIZE,MOUNTPOINT | awk '$NF!="/"{printf "%-15s%-10s\n", $1,$2}';
NAME           SIZE      
sda            57.3G     
|-sda1         512M      
|-sda2         488M      
`-sda3         56.3G     
`-sdb3_crypt   56.3G     
`-desktop--vg-swap_1980M      
nvme0n1        238.5G
$ lsblk -o NAME,SIZE,MOUNTPOINT | awk '$NF=="/"' |-desktop--vg-root 55.3G / ##### From Chris Davies RESULT:
Root partition: mapper/desktop--vg-root
Root device: 
NAME      SIZE
sda      57.3G
nvme0n1 238.5G
##### From @muru: lsblk -d $(findmnt -no source /)
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
desktop--vg-root 254:1    0 55,3G  0 lvm  /
Asked by ReflectYourCharacter (8185 rep)
Mar 27, 2025, 01:50 PM
Last activity: Jun 29, 2025, 01:15 PM