forked from openzfs/zfs
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contrib: dracut: fix race with root=zfs:dset when necessities required
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. Backport-of: 3399a30 Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
- Loading branch information
1 parent
d3f3776
commit 4ad1a21
Showing
9 changed files
with
54 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
[Unit] | ||
Description=Set BOOTFS environment for dracut | ||
Documentation=man:zpool(8) | ||
Description=Set BOOTFS and BOOTFSFLAGS environment variables for dracut | ||
DefaultDependencies=no | ||
After=zfs-import-cache.service | ||
After=zfs-import-scan.service | ||
Before=zfs-import.target | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/bin/sh -c "exec systemctl set-environment BOOTFS=$(@sbindir@/zpool list -H -o bootfs | grep -m1 -vFx -)" | ||
ExecStart=/bin/sh -c ' \ | ||
. /lib/dracut-zfs-lib.sh; \ | ||
decode_root_args || exit 0; \ | ||
[ "$root" = "zfs:AUTO" ] && root="$(@sbindir@/zpool list -H -o bootfs | grep -m1 -vFx -)"; \ | ||
rootflags="$(getarg rootflags=)"; \ | ||
case ",$rootflags," in \ | ||
*,zfsutil,*) ;; \ | ||
,,) rootflags=zfsutil ;; \ | ||
*) rootflags="zfsutil,$rootflags" ;; \ | ||
esac; \ | ||
exec systemctl set-environment BOOTFS="$root" BOOTFSFLAGS="$rootflags"' | ||
|
||
[Install] | ||
WantedBy=zfs-import.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[Unit] | ||
Before=initrd-root-fs.target | ||
After=sysroot.mount | ||
DefaultDependencies=no | ||
ConditionEnvironment=BOOTFS | ||
|
||
[Service] | ||
Type=oneshot | ||
PassEnvironment=BOOTFS | ||
ExecStart=/bin/sh -c ' \ | ||
. /lib/dracut-zfs-lib.sh; \ | ||
_zfs_nonroot_necessities_cb() { \ | ||
@sbindir@/zfs mount | grep -m1 -q "^$1 " && return 0; \ | ||
echo "Mounting $1 on /sysroot$2"; \ | ||
mount -o zfsutil -t zfs "$1" "/sysroot$2"; \ | ||
}; \ | ||
for_relevant_root_children "${BOOTFS}" _zfs_nonroot_necessities_cb' | ||
|
||
[Install] | ||
RequiredBy=initrd-root-fs.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters