Solutons Lounge

lvm – How to get name of loop device that contains a LUKS-encrypted logical volume


In Ubuntu, I have mounted a raw disk .img file as a loop device that contains a LUKS encrypted LVM with an Ubuntu install on it.

It is mounted like so: (output is from lsblk -o NAME,PKNAME,KNAME,FSTYPE,SIZE /dev/loop0

NAME                      PKNAME KNAME FSTYPE        SIZE
loop0                            loop0               240G
├─loop0p1                 loop0  dm-11 ext4          487M
├─loop0p2                 loop0  dm-12                 1K
└─loop0p5                 loop0  dm-13 crypto_LUKS 239.5G
  └─cloneluks             dm-13  dm-14 LVM2_member 239.5G
    ├─ubuntuclone-lv_swap dm-14  dm-15                 8G
    └─ubuntuclone-lv_root dm-14  dm-16 ext4        231.5G

Is there any command that I can use in a script to return the root “block device” (I’m not sure if that’s the correct term), when I give the mounted LV name?

I was hoping that lsblk -no pkname /dev/ubuntuclone/lv_root would work, but it outputs nothing – using kname gives me dm-16.

I want to get to loop0.

I also saw this answer which implied I could use "$(basename "$(readlink -f /dev/VG/LV)")", but I couldn’t work out how to use it:

 dev=/dev/ubuntuclone/lv_root ; echo "$(basename "$(readlink -f $dev)")"

outputs dm-16.

I can’t work out how to get “past” the crypto_LUKS container.

This is what I’m looking for:

for input:

/dev/ubuntuclone/lv_root or ubuntuclone-lv_root

I would like to get output:

/dev/loop0

Thanks.

edit: I think using lsblk --json | jq might be exactly what I want, but I’m having a lot of trouble working out the correct incantations for jq



Source link

Exit mobile version