0

This is my lsblk output:

NAME          MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
nvme0n1       259:0    0 465.8G  0 disk  
├─nvme0n1p1   259:1    0   512M  0 part  /efi
├─nvme0n1p2   259:2    0   420G  0 part  
│ └─cryptroot 254:0    0   420G  0 crypt /
└─nvme0n1p3   259:3    0  45.3G  0 part

I need to retrieve the "part" whose "crypt" is associated to the mountpoint "/", without knowing the "crypt" or the "part" beforehand:

nvme0n1p2 /

Can this be achieved in a single command?

1 Answer 1

0

lsblk can output JSON which you can pipe to jq. jq is a JSON processor and you can do any number of complex queries with it. So something like this should work:

lsblk --json | \
  jq -r '.blockdevices[] | .children[] | select( .. | objects | .mountpoints[]? == "/" ) | .name'

For example:

$ lsblk
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
nvme0n1             259:0    0 953.9G  0 disk  
├─nvme0n1p1         259:1    0   512M  0 part  /boot/efi
├─nvme0n1p2         259:2    0   3.9G  0 part  /boot
└─nvme0n1p3         259:3    0 949.5G  0 part  
  └─nvme0n1p3_crypt 253:0    0 949.5G  0 crypt /

$ lsblk --json | \
  jq -r '.blockdevices[] | .children[] | select( .. | objects | .mountpoints[]? == "/" ) | .name'
nvme0n1p3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .