diff --git a/contrib/dracut/90zfs/zfs-env-bootfs.service.in b/contrib/dracut/90zfs/zfs-env-bootfs.service.in index 7ebab4c1a58d..866b1c289ef4 100644 --- a/contrib/dracut/90zfs/zfs-env-bootfs.service.in +++ b/contrib/dracut/90zfs/zfs-env-bootfs.service.in @@ -11,12 +11,7 @@ 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; \ + determine_rootflags; \ exec systemctl set-environment BOOTFS="$root" BOOTFSFLAGS="$rootflags"' [Install] diff --git a/contrib/dracut/90zfs/zfs-lib.sh.in b/contrib/dracut/90zfs/zfs-lib.sh.in index 7139e2e6fe4b..a214b7105dcb 100755 --- a/contrib/dracut/90zfs/zfs-lib.sh.in +++ b/contrib/dracut/90zfs/zfs-lib.sh.in @@ -118,3 +118,19 @@ decode_root_args() { return 1 } + +# Gets rootflags and adds zfsutil for non-legacy mountpoints. +# Requires that decode_root_args() has already been called and $root is set. +determine_rootflags() { + rootflags="$(getarg rootflags=)" + + mountpoint="$(zfs get -H -o value mountpoint "$root")" + + if [ "$mountpoint" != legacy ]; then + case ",$rootflags," in + *,zfsutil,*) ;; + ,,) rootflags=zfsutil ;; + *) rootflags="zfsutil,$rootflags" ;; + esac + fi +}