From 72abbe49a433d71ea1a50a88662f52f5b94e1639 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 1 Apr 2021 12:08:58 -0500 Subject: [PATCH 08/10] 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. --- udev/pvscan-udev-initrd.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 udev/pvscan-udev-initrd.sh diff --git a/udev/pvscan-udev-initrd.sh b/udev/pvscan-udev-initrd.sh new file mode 100644 index 0000000..1743771 --- /dev/null +++ b/udev/pvscan-udev-initrd.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# 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 + +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 complete +# VG incomplete +# LV complete +# LV 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=$(/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 \' + -- 1.8.3.1