From 9c52dadbddd4db5cb47a2dea9152e840b4bdc8ae Mon Sep 17 00:00:00 2001 From: theQuestionmark <17354322+theQuestionmark@users.noreply.github.com> Date: Thu, 9 Jun 2022 16:59:04 +0200 Subject: [PATCH 1/3] initramfs: fix import of additional zpools on boot Currently all zpools defined in ZFS_INITRD_ADDITIONAL_DATASETS aren't imported correctly if they are on an other zpool than the root-pool. The mount fails hence the zpool is not known. Initramfs asks know for the second decryption-key on boot for second zpool. Signed-off-by: theQuestionmark <17354322+theQuestionmark@users.noreply.github.com> --- contrib/initramfs/scripts/zfs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contrib/initramfs/scripts/zfs b/contrib/initramfs/scripts/zfs index 1c8c496a7f..1ea5abe90b 100644 --- a/contrib/initramfs/scripts/zfs +++ b/contrib/initramfs/scripts/zfs @@ -897,6 +897,15 @@ mountroot() ZFS_RPOOL="${pool}" fi + # We need to import additional zpools which aren't under root zpool, before mount_fs() + for add_zpool in $ZFS_INITRD_ADDITIONAL_DATASETS; do + add_zpool_base="${add_zpool%%/*}" + + if [ "$add_zpool_base" != "$ZFS_RPOOL" ] + then + import_pool "${add_zpool_base}" + fi + done # ---------------------------------------------------------------- # P R E P A R E R O O T F I L E S Y S T E M From 18dff34a3845a05736cf417dbc74402b06ab06c4 Mon Sep 17 00:00:00 2001 From: theQuestionmark <17354322+theQuestionmark@users.noreply.github.com> Date: Sun, 12 Jun 2022 00:44:11 +0200 Subject: [PATCH 2/3] initramfs: add function to zfsexpandknowledge Adding function for honoring the ZFS_INITRD_ADDITIONAL_DATASETS variable. Signed-off-by: theQuestionmark <17354322+theQuestionmark@users.noreply.github.com> --- .../02zfsexpandknowledge/module-setup.sh.in | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in b/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in index df8df3181f..d9beb47199 100755 --- a/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in +++ b/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in @@ -50,6 +50,24 @@ find_zfs_block_devices() { done < /proc/self/mountinfo } +find_add_zpool_mps() { + local dev + local mp + local fstype + local _ + numfields="$(awk '{print NF; exit}' /proc/self/mountinfo)" + if [ "$numfields" = "10" ] ; then + fields="_ _ _ _ mp _ _ fstype dev _" + else + fields="_ _ _ _ mp _ _ _ fstype dev _" + fi + # shellcheck disable=SC2086 + while read -r ${fields?} ; do + [ "$fstype" = "zfs" ] || continue + [ "$dev" = "$1" ] && echo "$mp" + done < /proc/self/mountinfo +} + array_contains () { local e for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done @@ -75,6 +93,14 @@ check() { # shellcheck disable=SC2154 if [ -n "$hostonly" ]; then + if [ -f /etc/default/zfs ]; then + . /etc/default/zfs + if [ -n "$ZFS_INITRD_ADDITIONAL_DATASETS" ]; then + for add_zpool in $ZFS_INITRD_ADDITIONAL_DATASETS; do + add_mps+=$(find_add_zpool_mps "$add_zpool") + done + fi + fi for mp in \ "/" \ "/etc" \ @@ -87,7 +113,8 @@ if [ -n "$hostonly" ]; then "/usr/sbin" \ "/usr/lib" \ "/usr/lib64" \ - "/boot"; + "/boot" \ + "${add_mps[@]}"; do mp=$(readlink -f "$mp") mountpoint "$mp" >/dev/null 2>&1 || continue From 9f2fd4682d50c83b3e05a8acccebcde0cb202c0e Mon Sep 17 00:00:00 2001 From: theQuestionmark <17354322+theQuestionmark@users.noreply.github.com> Date: Sun, 12 Jun 2022 01:35:47 +0200 Subject: [PATCH 3/3] initramfs: dracut - Change to some make-variables Change /etc/ to sysconfdir-variable and add default-config to dracut initrd-image Signed-off-by: theQuestionmark <17354322+theQuestionmark@users.noreply.github.com> --- contrib/dracut/02zfsexpandknowledge/module-setup.sh.in | 4 ++-- contrib/dracut/90zfs/module-setup.sh.in | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in b/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in index d9beb47199..2fa25c57e9 100755 --- a/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in +++ b/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in @@ -93,8 +93,8 @@ check() { # shellcheck disable=SC2154 if [ -n "$hostonly" ]; then - if [ -f /etc/default/zfs ]; then - . /etc/default/zfs + if [ -f @sysconfdir@/default/zfs ]; then + . @sysconfdir@/default/zfs if [ -n "$ZFS_INITRD_ADDITIONAL_DATASETS" ]; then for add_zpool in $ZFS_INITRD_ADDITIONAL_DATASETS; do add_mps+=$(find_add_zpool_mps "$add_zpool") diff --git a/contrib/dracut/90zfs/module-setup.sh.in b/contrib/dracut/90zfs/module-setup.sh.in index 81d7d2abe4..e81861ae66 100755 --- a/contrib/dracut/90zfs/module-setup.sh.in +++ b/contrib/dracut/90zfs/module-setup.sh.in @@ -64,7 +64,8 @@ install() { # -o ensures there is no error upon absence of these files inst_multiple -o -H \ "@sysconfdir@/zfs/zpool.cache" \ - "@sysconfdir@/zfs/vdev_id.conf" + "@sysconfdir@/zfs/vdev_id.conf" \ + "@sysconfdir@/default/zfs" # Synchronize initramfs and system hostid if ! inst_simple -H @sysconfdir@/hostid; then