For non-interactive work, this can be done using dmsetup deps, which lists the block device's dependencies. By default, it'll return the major:minor device numbers, but you can provide additional options to output a name:
dmsetup deps -o devname /dev/mapper/decrypted
For doing this interactively, the best way is just to use lsblk, which outputs a nicely formatted graph:
Best Answer
Summary
Given a relative
$pathname
, the following commands will set the following variables:Absolute pathname
Mountpoint and device
Note: btrfs and zfs filesystems may span multiple devices, but only one will be listed here.
LV and VG names
There is no need to worry about possible whitspaces in names as man lvm(8) says:
PV devices
There may be more than one PV hosting your VG.
To deal with the edge case of special characters in device names, look into parsing
pvs --reportformat json
.Bonus: Loop device backing file