mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-21 22:04:19 +03:00
c229e321da
pvscan-udev-initrd.sh is shell wrapper around the pvscan command for use in the initrd lvm udev rule. It 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. 64-lvm.rules calls pvscan-udev-initrd.sh/pvscan to scan the PV to check if any VG or LVs are complete given the new device. The pvscan will only ever read the single device triggering the uevent. If any VG or LVs are complete, the udev rule uses systemd-run to run a vgchange or lvchange command to activate the complete VG or LVs. (Running vgchange or lvchange directly may take longer than udev likes, so systemd-run --no-block is used.)
58 lines
1.3 KiB
Bash
Executable File
58 lines
1.3 KiB
Bash
Executable File
#!/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 <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=$(/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 \'
|
|
|