]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
feat(dracut): add zfs detection
authorSavyasachee Jha <genghizkhan91@hawkradius.com>
Thu, 17 Feb 2022 19:26:03 +0000 (00:56 +0530)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Mon, 28 Feb 2022 21:22:38 +0000 (21:22 +0000)
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 <hi@savyasacheejha.com>
dracut-functions.sh
dracut.sh
modules.d/95rootfs-block/module-setup.sh

index 8503c22f6a3f63ebbe2f3821e59b66af306ebda6..febfe270b649f6a36fa2ac2f607551bcd5b3d83e 100755 (executable)
@@ -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")
index afc6fd04c9f386cf5aa6002186468698fe8146fe..955740dc2dd95079de388c08d1f82572516d67ba 100755 (executable)
--- 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"
             ;;
index 4931c6a21bdf3f8f90bb9a8350b7ffd6cd530718..396fb11e8d002bd7a6be91f8d3c0861bc82234fb 100755 (executable)
@@ -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"