mirror_zfs/contrib/initramfs/scripts/local-top/zfs
Friedrich Weber 047803e906
contrib/initramfs: use LVM autoactivation for activating VGs (#17125)
Currently, the zfs initramfs-tools boot script under local-top calls
`vgchange -ay`, which unconditionally activates all logical volumes
(LVs) in all discovered volume groups (VGs). This causes all LVs to be
active after boot. However, users may prefer to not activate certain
VGs/LVs on boot. They might normally use the `--setautoactivation n`
VG/LV flag or the `auto_activation_volume_list` LVM config option to
achieve this, but since the script unconditionally activates all LVs,
neither has an effect.

To fix this, call `vgchange -aay` instead. This triggers LVM
autoactivation, which honors autoactivation settings such as the
`--setautoactivation` flag. It is also more in line with the LVM
documentation, which says autoactivation is "meant to be used by
activation commands that are run automatically by the system" [1].

Note that this change might break misconfigured setups that have ZFS
on top of an LV for which autoactivation is disabled.

[1] https://gitlab.com/lvmteam/lvm2/-/blob/cff93e4d/conf/example.conf.in#L1579


Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>

Signed-off-by: Friedrich Weber <f.weber@proxmox.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
2025-04-01 16:07:46 -07:00

54 lines
985 B
Bash
Executable File

#!/bin/sh
# shellcheck disable=SC2154
if [ "$1" = "prereqs" ]; then
echo mdadm mdrun multipath
exit 0
fi
#
# Helper functions
#
message()
{
if plymouth --ping 2>/dev/null; then
plymouth message --text="$*"
else
echo "$*" >&2
fi
return 0
}
udev_settle()
{
# Wait for udev to be ready, see https://launchpad.net/bugs/85640
if [ -x /sbin/udevadm ]; then
/sbin/udevadm settle --timeout=30
elif [ -x /sbin/udevsettle ]; then
/sbin/udevsettle --timeout=30
fi
return 0
}
activate_vg()
{
# Sanity checks
if [ ! -x /sbin/lvm ]; then
[ "$quiet" != "y" ] && message "lvm is not available"
return 1
fi
# Detect and auto-activate available volume groups
/sbin/lvm vgscan
/sbin/lvm vgchange -aay --sysinit
return $?
}
udev_settle
activate_vg
exit 0