mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-26 11:19:32 +03:00
f8e87e205c
When Dracut starts up, it needs to determine whether a pool will remain "hanging open" before the system shuts off. In such a case, then the code to clean up the pool (using the previous export -F work) must be invoked. Since Dracut has had a recent change that makes mount-zfs.sh simply not run when the root dataset is already mounted, we must use the cleanup hook to order Dracut to do shutdown cleanup. Important note: this code will not accomplish its stated goal until this bug is fixed: https://bugzilla.redhat.com/show_bug.cgi?id=1385432 That bug impacts more than just ZFS. It impacts LUKS, dmraid, and unmount during poweroff. It is a Fedora-wide bug. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Manuel Amador (Rudd-O) <rudd-o@rudd-o.com> Closes #5287
70 lines
1.8 KiB
Bash
Executable File
70 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
. /lib/dracut-zfs-lib.sh
|
|
|
|
ZFS_DATASET=""
|
|
ZFS_POOL=""
|
|
|
|
case "${root}" in
|
|
zfs:*) ;;
|
|
*) return ;;
|
|
esac
|
|
|
|
GENERATOR_FILE=/run/systemd/generator/sysroot.mount
|
|
GENERATOR_EXTENSION=/run/systemd/generator/sysroot.mount.d/zfs-enhancement.conf
|
|
|
|
if [ -e "$GENERATOR_FILE" -a -e "$GENERATOR_EXTENSION" ] ; then
|
|
# If the ZFS sysroot.mount flag exists, the initial RAM disk configured
|
|
# it to mount ZFS on root. In that case, we bail early. This flag
|
|
# file gets created by the zfs-generator program upon successful run.
|
|
info "ZFS: There is a sysroot.mount and zfs-generator has extended it."
|
|
info "ZFS: Delegating root mount to sysroot.mount."
|
|
# Let us tell the initrd to run on shutdown.
|
|
# We have a shutdown hook to run
|
|
# because we imported the pool.
|
|
# We now prevent Dracut from running this thing again.
|
|
for zfsmounthook in "$hookdir"/mount/*zfs* ; do
|
|
if [ -f "$zfsmounthook" ] ; then
|
|
rm -f "$zfsmounthook"
|
|
fi
|
|
done
|
|
return
|
|
fi
|
|
info "ZFS: No sysroot.mount exists or zfs-generator did not extend it."
|
|
info "ZFS: Mounting root with the traditional mount-zfs.sh instead."
|
|
|
|
# Delay until all required block devices are present.
|
|
udevadm settle
|
|
|
|
if [ "${root}" = "zfs:AUTO" ] ; then
|
|
ZFS_DATASET="$(find_bootfs)"
|
|
if [ $? -ne 0 ] ; then
|
|
zpool import -N -a ${ZPOOL_IMPORT_OPTS}
|
|
ZFS_DATASET="$(find_bootfs)"
|
|
if [ $? -ne 0 ] ; then
|
|
warn "ZFS: No bootfs attribute found in importable pools."
|
|
export_all -F
|
|
|
|
rootok=0
|
|
return 1
|
|
fi
|
|
fi
|
|
info "ZFS: Using ${ZFS_DATASET} as root."
|
|
fi
|
|
|
|
ZFS_DATASET="${ZFS_DATASET:-${root#zfs:}}"
|
|
ZFS_POOL="${ZFS_DATASET%%/*}"
|
|
|
|
if import_pool "${ZFS_POOL}" ; then
|
|
# Let us tell the initrd to run on shutdown.
|
|
# We have a shutdown hook to run
|
|
# because we imported the pool.
|
|
info "ZFS: Mounting dataset ${ZFS_DATASET}..."
|
|
if mount_dataset "${ZFS_DATASET}" ; then
|
|
ROOTFS_MOUNTED=yes
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
rootok=0
|