3 # run lvm scan if udev has settled
6 type getarg
>/dev
/null
2>&1 || .
/lib
/dracut-lib.sh
8 VGS
=$
(getargs rd.lvm.vg
-d rd_LVM_VG
=)
9 LVS
=$
(getargs rd.lvm.lv
-d rd_LVM_LV
=)
10 SNAPSHOT
=$
(getargs rd.lvm.snapshot
-d rd_LVM_SNAPSHOT
=)
11 SNAPSIZE
=$
(getargs rd.lvm.snapsize
-d rd_LVM_SNAPSIZE
=)
13 [ -d /etc
/lvm
] || mkdir
-m 0755 -p /etc
/lvm
14 # build a list of devices to scan
16 for f
in /tmp
/.lvm_scan-
*; do
17 [ -e "$f" ] ||
continue
18 printf '%s' "${f##/tmp/.lvm_scan-} "
22 if [ ! -e /etc
/lvm
/lvm.conf
]; then
26 for dev
in $lvmdevs; do
27 printf '"a|^/dev/%s$|", ' $dev;
32 # establish LVM locking
33 if [ -n $SNAPSHOT ]; then
35 echo ' locking_type = 1';
36 echo ' use_lvmetad = 0';
40 echo ' locking_type = 4';
41 echo ' use_lvmetad = 0';
52 # --poll is supported since 2.2.57
53 [ $4 -lt $maj ] && return 1
54 [ $4 -gt $maj ] && return 0
55 [ $5 -lt $min ] && return 1
56 [ $5 -gt $min ] && return 0
57 [ $6 -ge $ver ] && return 0
61 # hopefully this output format will never change, e.g.:
62 # LVM version: 2.02.53(1) (2009-09-25)
65 set $
(lvm version
2>/dev
/null
)
72 lvm_ignorelockingfailure
="--ignorelockingfailure"
73 lvm_quirk_args
="--ignorelockingfailure --ignoremonitoring"
75 check_lvm_ver
2 2 57 $maj $min $sub && \
76 lvm_quirk_args
="$lvm_quirk_args --poll n"
78 if check_lvm_ver
2 2 65 $maj $min $sub; then
79 lvm_quirk_args
=" --sysinit $extraargs"
82 if check_lvm_ver
2 2 221 $maj $min $sub; then
83 lvm_quirk_args
=" $extraargs"
84 unset lvm_ignorelockingfailure
89 export LVM_SUPPRESS_LOCKING_FAILURE_MESSAGES
=1
91 if [ -n "$SNAPSHOT" ] ; then
92 # HACK - this should probably be done elsewhere or turned into a function
93 # Enable read-write LVM locking
94 sed -i -e 's/\(^[[:space:]]*\)locking_type[[:space:]]*=[[:space:]]*[[:digit:]]/\1locking_type = 1/' ${initdir}/etc
/lvm
/lvm.conf
96 # Expected SNAPSHOT format "<orig lv name>:<snap lv name>"
97 ORIG_LV
=${SNAPSHOT%%:*}
98 SNAP_LV
=${SNAPSHOT##*:}
100 info
"Removing existing LVM snapshot $SNAP_LV"
101 lvm lvremove
--force $SNAP_LV 2>&1| vinfo
103 # Determine snapshot size
104 if [ -z "$SNAPSIZE" ] ; then
105 SNAPSIZE
=$
(lvm lvs
--noheadings --units m
--options lv_size
$ORIG_LV)
106 info
"No LVM snapshot size provided, using size of $ORIG_LV ($SNAPSIZE)"
109 info
"Creating LVM snapshot $SNAP_LV ($SNAPSIZE)"
110 lvm lvcreate
-s -n $SNAP_LV -L $SNAPSIZE $ORIG_LV 2>&1| vinfo
113 if [ -n "$LVS" ] ; then
114 info
"Scanning devices $lvmdevs for LVM logical volumes $LVS"
115 lvm lvscan
$lvm_ignorelockingfailure 2>&1 | vinfo
117 lvm lvchange
--yes -K -ay $lvm_quirk_args $LV 2>&1 | vinfo
121 if [ -z "$LVS" -o -n "$VGS" ]; then
122 info
"Scanning devices $lvmdevs for LVM volume groups $VGS"
123 lvm vgscan
$lvm_ignorelockingfailure 2>&1 | vinfo
124 lvm vgchange
-ay $lvm_quirk_args $VGS 2>&1 | vinfo
127 if [ "$lvmwritten" ]; then
128 rm -f -- /etc
/lvm
/lvm.conf