summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2021-04-01 12:08:58 -0500
committerDavid Teigland <teigland@redhat.com>2021-04-01 13:17:07 -0500
commit2ed8f23ae340b573ea0fd2dbf6529b9f6497dae0 (patch)
tree8779586cfe553686c02af69341ea80dd7fd2bb99
parent84607d93b6a2440be0b04dba15a716a718a39666 (diff)
downloadlvm2-2ed8f23ae340b573ea0fd2dbf6529b9f6497dae0.tar.gz
add pvscan-udev-initrd.sh
pvscan wrapper for use in the initrd lvm udev rule. Finds the intersection of complete VG/LVs reported by pvscan, and the VG/LVs specified on boot cmdline. The resulting VG or LVs are printed as env-vars that the udev rule can IMPORT, and pass to vgchange/lvchange.
-rw-r--r--udev/pvscan-udev-initrd.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/udev/pvscan-udev-initrd.sh b/udev/pvscan-udev-initrd.sh
new file mode 100644
index 000000000..60f90010e
--- /dev/null
+++ b/udev/pvscan-udev-initrd.sh
@@ -0,0 +1,57 @@
+# pvscan wrapper called by initrd lvm udev rule to find the
+# intersection of complete VGs/LVs found by pvscan and the
+# requested VGs/LVs from the cmdline.
+#
+# Used in 64-lvm.rules as:
+# IMPORT{program}="pvscan-udev-initrd.sh $env{DEVNAME}"
+#
+# See /usr/lib/dracut/modules.d/90lvm/64-lvm.rules
+
+#!/bin/sh
+
+dev=$1
+
+type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
+
+
+VGS=$(getargs rd.lvm.vg -d rd_LVM_VG=)
+LVS=$(getargs rd.lvm.lv -d rd_LVM_LV=)
+
+IFS=' '
+
+# pvscan will produce a single VG line, and one or more LV lines.
+# VG <name> complete
+# VG <name> incomplete
+# LV <name> complete
+# LV <name> incomplete
+#
+# LV names are printed as vgname/lvname.
+# We only care about the complete items.
+# Each pvscan will produce a single VG line,
+# and may produce zero, one or more LV lines.
+
+PVSCAN=$(/usr/sbin/lvm pvscan --cache --listlvs --checkcomplete --journal output --config 'global/event_activation=1' $dev)
+
+read -r -a VGSARRAY <<< "$VGS"
+
+for VG in "${VGSARRAY[@]}"
+do
+ if strstr "$PVSCAN" "VG $VG complete" ; then
+ echo LVM_VG_NAME_COMPLETE=\'"$VG"\'
+ fi
+done
+
+# Combine all matching LVs into a single print containing them all,
+# e.g. LVM_LV_NAMES_COMPLETE='vg/lv1 vg/lv2'
+
+read -r -a LVSARRAY <<< "$LVS"
+
+echo -n LVM_LV_NAMES_COMPLETE=\'
+for LV in "${LVSARRAY[@]}"
+do
+ if strstr "$PVSCAN" "LV $LV complete" ; then
+ echo -n "$LV "
+ fi
+done
+echo \'
+