3 which pvdisplay >/dev/null 2>&1 && pvdisplay $device >/dev/null 2>&1
8 echo " LVM (linear allocation scheme)"
25 echo "# $device: LVM detected" 1>&2
27 # Step 3: Get pysical extent number
29 pvname="`pvdisplay -c $device 2>/dev/null | awk -F: '{print $1,$2,$8}' | sed -e 's/^ *//'`"
31 if [ -z "$pvname" ]; then
32 echo "! $device is not a physical volume" 1>&2
36 pesize="${pvname##* }"
40 pesize="`dc -e "$pesize 2 * p"`" #`"
41 pestart="`pvs --unit s -ope_start $device 2>/dev/null | sed -n -e 's/ *//g' -e 's/S.*$//' -e '$p'`"
42 penum="`dc -e "$sector $pestart - $pesize ~ n [ ] n p"`" #`"
43 subsector="${penum% *}"
46 echo "device $pvname pv"
47 echo "offset $pestart"
50 echo "subsector $subsector"
53 # Step 4: Find associated logical volume
55 lestart="$(vgdisplay -v $vgname 2>/dev/null | awk '/LV Name/{print $3}' | while read lvname; do \
56 lvdisplay -m $lvname 2>/dev/null \
57 | awk -v RS="\n *\n( --- Segments ---\n)?" \
62 '$0 ~ "Physical volume[ \t]+" pvname && $14<=penum && $16>=penum{print lvname,$4,$14}'; \
65 if [ -z "$lestart" ]; then
66 echo "# pysical extent $penum of $pvname is not mapped in any logical volume" 1>&2
70 lvname="${lestart%% *}"
71 lestart="${lestart#* }"
72 firstpe="${lestart#* }"
73 lestart="${lestart% *}"
74 lenum="`dc -e "$penum $firstpe - $lestart + p"`" #`"
76 echo "device $lvname lv"
80 fssector="`dc -e "$lenum $pesize * $subsector + p"`" #`"
82 echo "sector $fssector"