From c7fbe08a97c8f37464fd924e87c602cbfee30e24 Mon Sep 17 00:00:00 2001 From: "Andrew J. Hesford" Date: Wed, 19 Feb 2025 07:11:13 -0500 Subject: [PATCH] mkinitcpio: improve zfs hook --- srcpkgs/mkinitcpio/files/zfs_hook | 48 ++++++++++++++++--------------- srcpkgs/mkinitcpio/template | 2 +- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/srcpkgs/mkinitcpio/files/zfs_hook b/srcpkgs/mkinitcpio/files/zfs_hook index 5d296293c16..9ef1ee9be10 100644 --- a/srcpkgs/mkinitcpio/files/zfs_hook +++ b/srcpkgs/mkinitcpio/files/zfs_hook @@ -105,30 +105,32 @@ zfs_mount_handler () { fi local node="$1" - local rootmnt=$(zfs get -H -o value mountpoint "${ZFS_DATASET}") - local tab_file="${node}/etc/fstab" - local zfs_datasets="$(zfs list -H -o name -t filesystem -r ${ZFS_DATASET})" + local rootopt="${rwopt_exp}${rootflags:+,${rootflags}}" + local mountpoint - # Mount the root, and any child datasets - for dataset in ${zfs_datasets}; do - mountpoint=$(zfs get -H -o value mountpoint "${dataset}") - canmount=$(zfs get -H -o value canmount "${dataset}") - # skip dataset - [ ${dataset} != "${ZFS_DATASET}" -a \( ${canmount} = "off" -o ${canmount} = "noauto" -o ${mountpoint} = "none" \) ] && continue - if [ ${mountpoint} = "legacy" ]; then - if [ -f "${tab_file}" ]; then - if findmnt -snero source -F "${tab_file}" -S "${dataset}" > /dev/null 2>&1; then - opt=$(findmnt -snero options -F "${tab_file}" -S "${dataset}") - mnt=$(findmnt -snero target -F "${tab_file}" -S "${dataset}") - zfs_decrypt_fs "${dataset}" - mount -t zfs -o "${opt}" "${dataset}" "${node}${mnt}" - fi - fi - else - zfs_decrypt_fs "${dataset}" - mount -t zfs -o "zfsutil,${rwopt_exp}" "${dataset}" "${node}/${mountpoint##${rootmnt}}" - fi - done + mountpoint="$(zfs list -H -o mountpoint "${ZFS_DATASET}")" || mountpoint= + [ "${mountpoint}" = "legacy" ] || rootopt="zfsutil,${rootopt}" + + # Decrypt (if needed) and mount the root + zfs_decrypt_fs "${ZFS_DATASET}" + mount -t zfs -o "${rootopt}" "${ZFS_DATASET}" "${node}" + + # Walk the tree looking for auto-mount /usr, just in case + local fs canmount + zfs list -H -o name,mountpoint,canmount -r -t filesystem "${pool}" \ + | while read -r fs mountpoint canmount; do + # Ignore all filesystems not marked for automatic mount + [ "${canmount}" = "on" ] || continue + # Ignore all mountpoints but /usr + [ "${mountpoint}" = "/usr" ] || continue + # Ignore the root filesystem that has just been mounted + [ "${fs}" = "${ZFS_DATASET}" ] && continue + + # Decrypt (if needed) and mount first automounted /usr filesystem + zfs_decrypt_fs "${fs}" + mount -o "zfsutil,${rwopt_exp}" "${fs}" "${node}/usr" + break + done } set_flags() { diff --git a/srcpkgs/mkinitcpio/template b/srcpkgs/mkinitcpio/template index 432ec3de9ed..187e26e2c45 100644 --- a/srcpkgs/mkinitcpio/template +++ b/srcpkgs/mkinitcpio/template @@ -1,7 +1,7 @@ # Template file for 'mkinitcpio' pkgname=mkinitcpio version=39.2 -revision=3 +revision=4 build_style=gnu-makefile hostmakedepends="asciidoc" depends="busybox-static bsdtar bash zstd"