Skip to content

Commit

Permalink
feat(dracut): add zfs detection
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
savyajha authored and johannbg committed Feb 28, 2022
1 parent 4c355d0 commit 9582f02
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dracut-functions.sh
Expand Up @@ -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")
Expand Down
17 changes: 17 additions & 0 deletions dracut.sh
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2588,6 +2602,9 @@ freeze_ok_for_fstype() {
msdos)
return 1
;;
zfs)
return 1
;;
btrfs)
freeze_ok_for_btrfs "$outfile"
;;
Expand Down
5 changes: 5 additions & 0 deletions modules.d/95rootfs-block/module-setup.sh
Expand Up @@ -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"
Expand Down

0 comments on commit 9582f02

Please sign in to comment.