From: Savyasachee Jha Date: Thu, 17 Feb 2022 19:26:03 +0000 (+0530) Subject: feat(dracut): add zfs detection X-Git-Tag: 057~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9582f02773c5115e14fe0992ec2db3935cb0e6eb;p=thirdparty%2Fdracut.git feat(dracut): add zfs detection zfs detection is currently done by the zfs dracut module installed by downstream, resulting in a lot of duplicated code. This commit puts zfs detection into the core dracut logic, allowing for detection of zfs partitions to be done at the same time as all others. It also allows for dracut to correctly create a `root=` cmdline parameter for zfs. Signed-off-by: Savyasachee Jha --- diff --git a/dracut-functions.sh b/dracut-functions.sh index 8503c22f6..febfe270b 100755 --- a/dracut-functions.sh +++ b/dracut-functions.sh @@ -780,6 +780,14 @@ btrfs_devs() { done } +zfs_devs() { + local _mp="$1" + zpool list -H -v -P "${_mp%%/*}" | awk -F$'\t' '$2 ~ /^\// {print $2}' \ + | while read -r _dev; do + realpath "${_dev}" + done +} + iface_for_remote_addr() { # shellcheck disable=SC2046 set -- $(ip -o route get to "$1") diff --git a/dracut.sh b/dracut.sh index afc6fd04c..955740dc2 100755 --- a/dracut.sh +++ b/dracut.sh @@ -1456,6 +1456,10 @@ for line in "${fstab_lines[@]}"; do push_host_devs "$i" done done + elif [[ $3 == zfs ]]; then + for mp in $(zfs_devs "$1"); do + push_host_devs "$mp" + done fi push_host_devs "$dev" host_fs_types["$dev"]="$3" @@ -1508,7 +1512,13 @@ if [[ $hostonly ]] && [[ $hostonly_default_device != "no" ]]; then [[ $mp == "/" ]] && root_devs+=("$i") push_host_devs "$i" done + elif [[ $(find_mp_fstype "$mp") == zfs ]]; then + for i in $(zfs_devs "$(findmnt -n -o SOURCE "$mp")"); do + [[ $mp == "/" ]] && root_devs+=("$i") + push_host_devs "$i" + done fi + done # TODO - with sysroot, /proc/swaps is not relevant @@ -1561,6 +1571,10 @@ if [[ $hostonly ]] && [[ $hostonly_default_device != "no" ]]; then for i in $(btrfs_devs "$_m"); do push_host_devs "$i" done + elif [[ $_t == zfs ]]; then + for i in $(zfs_devs "$_d"); do + push_host_devs "$i" + done fi done < "$dracutsysrootdir"/etc/fstab fi @@ -2588,6 +2602,9 @@ freeze_ok_for_fstype() { msdos) return 1 ;; + zfs) + return 1 + ;; btrfs) freeze_ok_for_btrfs "$outfile" ;; diff --git a/modules.d/95rootfs-block/module-setup.sh b/modules.d/95rootfs-block/module-setup.sh index 4931c6a21..396fb11e8 100755 --- a/modules.d/95rootfs-block/module-setup.sh +++ b/modules.d/95rootfs-block/module-setup.sh @@ -44,6 +44,11 @@ cmdline_rootfs() { printf " root=%s" "$(shorten_persistent_dev "$(get_persistent_dev "$_dev")")" fi _fstype="$(find_mp_fstype /)" + if [[ ${_fstype} == "zfs" ]]; then + local _root_ds + _root_ds="$(findmnt -n -o SOURCE /)" + printf " root=zfs:%s" "${_root_ds// /+}" + fi _flags="$(find_mp_fsopts /)" if [ -n "$_fstype" ]; then printf " rootfstype=%s" "$_fstype"