mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-26 03:09:34 +03:00
3399a30ee0
This had always worked in my testing, but a user on hardware reported this to happen 100%, and I reproduced it once with cold VM host caches. dracut-zfs-generator runs as a systemd generator, i.e. at Some Relatively Early Time; if root= is a fixed dataset, it tries to "solve [necessities] statically at generation time". If by that point zfs-import.target hasn't popped (because the import is taking a non-negligible amount of time for whatever reason), it'll see no children for the root datase, and as such generate no mounts. This has never had any right to work. No-one caught this earlier because it's just that much more convenient to have root=zfs:AUTO, which orders itself properly. To fix this, always run zfs-nonroot-necessities.service; this additionally simplifies the implementation by: * making BOOTFS from zfs-env-bootfs.service be the real, canonical, root dataset name, not just "whatever the first bootfs is", and only set it if we're ZFS-booting * zfs-{rollback,snapshot}-bootfs.service can use this instead of re-implementing it * having zfs-env-bootfs.service also set BOOTFSFLAGS * this means the sysroot.mount drop-in can be fixed text * zfs-nonroot-necessities.service can also be constant and always enabled, because it's conditioned on BOOTFS being set There is no longer any code generated at run-time (the sysroot.mount drop-in is an unavoidable gratuitous cp). The flow of BOOTFS{,FLAGS} from zfs-env-bootfs.service to sysroot.mount is not noted explicitly in dracut.zfs(7), because (a) at some point it's just visual noise and (b) it's already ordered via d-p-m.s from z-i.t. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #14690
43 lines
1.2 KiB
Bash
Executable File
43 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# shellcheck disable=SC2016,SC1004,SC2154
|
|
|
|
grep -wq debug /proc/cmdline && debug=1
|
|
[ -n "$debug" ] && echo "zfs-generator: starting" >> /dev/kmsg
|
|
|
|
GENERATOR_DIR="$1"
|
|
[ -n "$GENERATOR_DIR" ] || {
|
|
echo "zfs-generator: no generator directory specified, exiting" >> /dev/kmsg
|
|
exit 1
|
|
}
|
|
|
|
# shellcheck source=zfs-lib.sh.in
|
|
. /lib/dracut-zfs-lib.sh
|
|
decode_root_args || exit 0
|
|
|
|
[ -n "$debug" ] && echo "zfs-generator: writing extension for sysroot.mount to $GENERATOR_DIR/sysroot.mount.d/zfs-enhancement.conf" >> /dev/kmsg
|
|
|
|
|
|
mkdir -p "$GENERATOR_DIR"/sysroot.mount.d "$GENERATOR_DIR"/dracut-pre-mount.service.d
|
|
|
|
{
|
|
echo "[Unit]"
|
|
echo "Before=initrd-root-fs.target"
|
|
echo "After=zfs-import.target"
|
|
echo
|
|
echo "[Mount]"
|
|
echo "PassEnvironment=BOOTFS BOOTFSFLAGS"
|
|
echo 'What=${BOOTFS}'
|
|
echo "Type=zfs"
|
|
echo 'Options=${BOOTFSFLAGS}'
|
|
} > "$GENERATOR_DIR"/sysroot.mount.d/zfs-enhancement.conf
|
|
ln -fs ../sysroot.mount "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount
|
|
|
|
{
|
|
echo "[Unit]"
|
|
echo "After=zfs-import.target"
|
|
} > "$GENERATOR_DIR"/dracut-pre-mount.service.d/zfs-enhancement.conf
|
|
|
|
[ -n "$debug" ] && echo "zfs-generator: finished" >> /dev/kmsg
|
|
|
|
exit 0
|