They are a completely random 192-bit identifier (c.f. 128 bits for RFC4122 UUID) that is used by LVM to uniquely identify each of its various entities: volume group, physical volume, logical volume.
As described here, this is generated from /dev/urandom
using the characters [a-zA-Z0-9]
. Note that this provides for 5.808 bits per character. According to the LVM2 source code, because LVM1 UUIDs didn't support them, the two extra characters supported by the format ("!" and "#") are not used during UUID generation.
The probability of duplicates is exceedingly low by extrapolating from the calculations on the Universally unique identifier page on Wikipedia.
Summary
Given a relative $pathname
, the following commands will set the following variables:
$absolute $mount $dev $lv $vg $pvs
Absolute pathname
absolute=$(readlink -f "$pathname")
Mountpoint and device
read -r dev mount <<< $(df --portability "$pathname" | awk 'NR==2{print $1 " " $6}')
Note: btrfs and zfs filesystems may span multiple devices, but only one will be listed here.
LV and VG names
read -r lv vg <<< $(sudo lvs -o lv_name,vg_name --noheadings "$dev")
There is no need to worry about possible whitspaces in names as man lvm(8) says:
The valid characters for VG and LV names are: a-z A-Z 0-9 + _ . -
PV devices
pvs=$(sudo vgs -o pv_name --noheadings "$vg")
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
backing=$(losetup -lnO BACK-FILE "$dev")
Best Answer
You can filter LVM commands’ output directly using the
-S
option:This also works with
vgs
andlvs
to find VGs and LVs.To avoid having to deal with the spaces at the start of the output, add
--config 'log{prefix=""}'
: