mkinitcpio: improve zfs hook

This commit is contained in:
Andrew J. Hesford 2025-02-19 07:11:13 -05:00 committed by classabbyamp
parent 36bbb58691
commit c7fbe08a97
2 changed files with 26 additions and 24 deletions

View file

@ -105,30 +105,32 @@ zfs_mount_handler () {
fi fi
local node="$1" local node="$1"
local rootmnt=$(zfs get -H -o value mountpoint "${ZFS_DATASET}") local rootopt="${rwopt_exp}${rootflags:+,${rootflags}}"
local tab_file="${node}/etc/fstab" local mountpoint
local zfs_datasets="$(zfs list -H -o name -t filesystem -r ${ZFS_DATASET})"
# Mount the root, and any child datasets mountpoint="$(zfs list -H -o mountpoint "${ZFS_DATASET}")" || mountpoint=
for dataset in ${zfs_datasets}; do [ "${mountpoint}" = "legacy" ] || rootopt="zfsutil,${rootopt}"
mountpoint=$(zfs get -H -o value mountpoint "${dataset}")
canmount=$(zfs get -H -o value canmount "${dataset}") # Decrypt (if needed) and mount the root
# skip dataset zfs_decrypt_fs "${ZFS_DATASET}"
[ ${dataset} != "${ZFS_DATASET}" -a \( ${canmount} = "off" -o ${canmount} = "noauto" -o ${mountpoint} = "none" \) ] && continue mount -t zfs -o "${rootopt}" "${ZFS_DATASET}" "${node}"
if [ ${mountpoint} = "legacy" ]; then
if [ -f "${tab_file}" ]; then # Walk the tree looking for auto-mount /usr, just in case
if findmnt -snero source -F "${tab_file}" -S "${dataset}" > /dev/null 2>&1; then local fs canmount
opt=$(findmnt -snero options -F "${tab_file}" -S "${dataset}") zfs list -H -o name,mountpoint,canmount -r -t filesystem "${pool}" \
mnt=$(findmnt -snero target -F "${tab_file}" -S "${dataset}") | while read -r fs mountpoint canmount; do
zfs_decrypt_fs "${dataset}" # Ignore all filesystems not marked for automatic mount
mount -t zfs -o "${opt}" "${dataset}" "${node}${mnt}" [ "${canmount}" = "on" ] || continue
fi # Ignore all mountpoints but /usr
fi [ "${mountpoint}" = "/usr" ] || continue
else # Ignore the root filesystem that has just been mounted
zfs_decrypt_fs "${dataset}" [ "${fs}" = "${ZFS_DATASET}" ] && continue
mount -t zfs -o "zfsutil,${rwopt_exp}" "${dataset}" "${node}/${mountpoint##${rootmnt}}"
fi # Decrypt (if needed) and mount first automounted /usr filesystem
done zfs_decrypt_fs "${fs}"
mount -o "zfsutil,${rwopt_exp}" "${fs}" "${node}/usr"
break
done
} }
set_flags() { set_flags() {

View file

@ -1,7 +1,7 @@
# Template file for 'mkinitcpio' # Template file for 'mkinitcpio'
pkgname=mkinitcpio pkgname=mkinitcpio
version=39.2 version=39.2
revision=3 revision=4
build_style=gnu-makefile build_style=gnu-makefile
hostmakedepends="asciidoc" hostmakedepends="asciidoc"
depends="busybox-static bsdtar bash zstd" depends="busybox-static bsdtar bash zstd"