mirror of
https://git.sr.ht/~nabijaczleweli/tzpfms
synced 2025-04-21 09:47:35 +03:00
86 lines
2.4 KiB
C
86 lines
2.4 KiB
C
# SPDX-License-Identifier: 0BSD
|
|
# dbda45160ffa43e5ecf0498a609230f1afee7b3f (zfs-2.2.99-270-gdbda45160)
|
|
|
|
|
|
# for_relevant_root_children DATASET EXEC
|
|
# Runs "EXEC dataset mountpoint" for all children of DATASET that are needed for system bringup
|
|
# Used by zfs-nonroot-necessities.service and friends, too!
|
|
for_relevant_root_children() {
|
|
dataset="${1}"
|
|
exec="${2}"
|
|
|
|
zfs list -t filesystem -Ho name,mountpoint,canmount -r "${dataset}" |
|
|
(
|
|
_ret=0
|
|
while IFS=" " read -r dataset mountpoint canmount; do
|
|
[ "$canmount" != "on" ] && continue
|
|
|
|
case "$mountpoint" in
|
|
/etc|/bin|/lib|/lib??|/libx32|/usr)
|
|
# If these aren't mounted we may not be able to get to the real init at all, or pollute the dataset holding the rootfs
|
|
"${exec}" "${dataset}" "${mountpoint}" || _ret=$?
|
|
;;
|
|
*)
|
|
# Up to the real init to remount everything else it might need
|
|
;;
|
|
esac
|
|
done
|
|
exit "${_ret}"
|
|
)
|
|
}
|
|
|
|
# Parse root=, rootfstype=, return them decoded and normalised to zfs:AUTO for auto, plain dset for explicit
|
|
#
|
|
# True if ZFS-on-root, false if we shouldn't
|
|
#
|
|
# Supported values:
|
|
# root=
|
|
# root=zfs
|
|
# root=zfs:
|
|
# root=zfs:AUTO
|
|
#
|
|
# root=ZFS=data/set
|
|
# root=zfs:data/set
|
|
# root=zfs:ZFS=data/set (as a side-effect; allowed but undocumented)
|
|
#
|
|
# rootfstype=zfs AND root=data/set <=> root=data/set
|
|
# rootfstype=zfs AND root= <=> root=zfs:AUTO
|
|
#
|
|
# '+'es in explicit dataset decoded to ' 's.
|
|
decode_root_args() {
|
|
if [ -n "$rootfstype" ]; then
|
|
[ "$rootfstype" = zfs ]
|
|
return
|
|
fi
|
|
|
|
xroot=$(getarg root=)
|
|
rootfstype=$(getarg rootfstype=)
|
|
|
|
# shellcheck disable=SC2249
|
|
case "$xroot" in
|
|
""|zfs|zfs:|zfs:AUTO)
|
|
root=zfs:AUTO
|
|
rootfstype=zfs
|
|
return 0
|
|
;;
|
|
|
|
ZFS=*|zfs:*)
|
|
root="${xroot#zfs:}"
|
|
root="${root#ZFS=}"
|
|
root=$(echo "$root" | tr '+' ' ')
|
|
rootfstype=zfs
|
|
return 0
|
|
;;
|
|
esac
|
|
|
|
if [ "$rootfstype" = "zfs" ]; then
|
|
case "$xroot" in
|
|
"") root=zfs:AUTO ;;
|
|
*) root=$(echo "$xroot" | tr '+' ' ') ;;
|
|
esac
|
|
return 0
|
|
fi
|
|
|
|
return 1
|
|
}
|