Skip to content

Commit

Permalink
zfsbootmenu: remove legacy root= usage/design
Browse files Browse the repository at this point in the history
ZFSBootMenu has danced around `$root` for a few years now, as a holdover from
very early design decisions picked up from Dracut. We don't actually _need_ to
tie ourselves to that variable - and in fact, a lot of the early startup process
can be simplified by no longer trying to stuff so much logic into it.

To that end, the legacy but undocumented support for
`root=zfsbootmenu:POOL=pool` has been completely removed. `root` on the ZBM KCL
is no longer honored. `zbm.prefer` with the documented syntax is now the only
way to tell ZFSBootMenu which pool should be preferentially used in the boot
process. Accordingly, the global `zbm_prefer_pool` variable is now set when a
pool should be preferred, and the accompanying `zbm_require_pool` variable is
used to indicate how firm that pool requirement is. One quirk of this is that a
pool name of `zfsbootmenu` can now actually be a value that `zbm.prefer` will
respect/honor.
  • Loading branch information
zdykstra committed Oct 5, 2023
1 parent 22032ed commit 57b5572
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 54 deletions.
2 changes: 1 addition & 1 deletion zfsbootmenu/lib/zfsbootmenu-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ match_hostid() {
state*)
state="${line#state: }"
# shellcheck disable=SC2154
if [ "${state}" == "ONLINE" ] && [ -n "${pool}" ] && [ "${pool}" != "${root}" ]; then
if [ "${state}" == "ONLINE" ] && [ -n "${pool}" ] && [ "${pool}" != "${zbm_prefer_pool}" ]; then
importable+=("${pool}")
pool=""
fi
Expand Down
30 changes: 13 additions & 17 deletions zfsbootmenu/libexec/zfsbootmenu-init
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,9 @@ fi
tput clear
/libexec/zfsbootmenu-run-hooks "early-setup.d"

# Prefer a specific pool when checking for a bootfs value
# shellcheck disable=SC2154
if [ "${root}" = "zfsbootmenu" ]; then
boot_pool=
else
boot_pool="${root}"
fi

# If a boot pool is specified, that will be tried first
try_pool="${boot_pool}"
# shellcheck disable=SC2154
try_pool="${zbm_prefer_pool}"
zbm_import_attempt=0

while true; do
Expand All @@ -126,7 +119,7 @@ while true; do

# shellcheck disable=SC2154
if check_for_pools; then
if [ "${zbm_require_bpool}" = "only" ]; then
if [ "${zbm_require_pool}" = "only" ]; then
zdebug "only importing ${try_pool}"
break
elif [ -n "${try_pool}" ]; then
Expand All @@ -148,15 +141,15 @@ while true; do
echo -n "$spl_hostid" > "${BASE}/spl_hostid"

# If match_hostid succeeds, it has imported *a* pool...
if [ -n "${try_pool}" ] && [ "${zbm_require_bpool}" = "only" ]; then
# In "only" bpool mode, the import was the sole pool desired; nothing more to do
if [ -n "${try_pool}" ] && [ "${zbm_require_pool}" = "only" ]; then
# In "only" pool mode, the import was the sole pool desired; nothing more to do
break
else
# Otherwise, try one more pass to pick up other pools matching this hostid
try_pool=""
continue
fi
elif [ -n "${try_pool}" ] && [ -z "${zbm_require_bpool}" ]; then
elif [ -n "${try_pool}" ] && [ -z "${zbm_require_pool}" ]; then
# If a specific pool was tried unsuccessfully but is not a requirement,
# allow another pass to try any other importable pools
try_pool=""
Expand Down Expand Up @@ -186,6 +179,7 @@ while IFS=$'\t' read -r _pool _health; do
zerror "prohibiting read/write operations on ${_pool}"
fi
done <<<"$( zpool list -H -o name,health )"
unset _pool _health

zdebug && zdebug "$( zreport )"

Expand All @@ -205,17 +199,19 @@ if [ "${unsupported}" -ne 0 ]; then
timed_prompt -m "$( colorize red 'Unsupported features detected')" \
-m "$( colorize red 'Upgrade ZFS modules in ZFSBootMenu with generate-zbm')"
fi
unset unsupported

# Attempt to find the bootfs property
# shellcheck disable=SC2086
while read -r line; do
if [ "${line}" = "-" ]; then
while read -r _bootfs; do
if [ "${_bootfs}" = "-" ]; then
BOOTFS=
else
BOOTFS="${line}"
BOOTFS="${_bootfs}"
break
fi
done <<<"$( zpool list -H -o bootfs ${boot_pool} )"
done <<<"$( zpool list -H -o bootfs "${zbm_prefer_pool:---}" )"
unset _bootfs

if [ -n "${BOOTFS}" ]; then
export BOOTFS
Expand Down
50 changes: 16 additions & 34 deletions zfsbootmenu/pre-init/zfsbootmenu-parse-commandline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ else
zinfo "disabling automatic replacement of spl_hostid"
fi

# rewrite root=
if prefer=$( get_zbm_arg zbm.prefer ) ; then
root="zfsbootmenu:POOL=${prefer}"
fi

if kcl_override=$( get_zbm_arg zbm.kcl_override ) ; then
# Remove the leading / trailing quote to "unpack" this argument
kcl_override="${kcl_override#\"}"
Expand All @@ -224,46 +219,33 @@ if kcl_override=$( get_zbm_arg zbm.kcl_override ) ; then
zinfo "overriding all BE KCLs with: '$( kcl_assemble < "${BASE}/cmdline" )'"
fi

wait_for_zfs=0
case "${root}" in
zfsbootmenu:POOL=*)
# Prefer a specific pool for bootfs value, root=zfsbootmenu:POOL=zroot
root="${root#zfsbootmenu:POOL=}"
# shellcheck disable=SC2034
rootok=1
wait_for_zfs=1

zinfo "preferring ${root} for bootfs"
;;
*)
root="zfsbootmenu"
# shellcheck disable=SC2034
rootok=1
wait_for_zfs=1

zinfo "enabling menu after udev settles"
;;
esac
zbm_prefer_pool=
if zbm_prefer_pool=$( get_zbm_arg zbm.prefer ) ; then
# shellcheck disable=SC2034
zbm_prefer_pool="${zbm_prefer_pool%%/*}"
zinfo "preferring ${zbm_prefer_pool} for bootfs"
fi

# pool! : this pool must be imported before all others
# pool!!: this pool, and no others, must be imported

# shellcheck disable=SC2034
case "${root}" in
case "${zbm_prefer_pool}" in
*!!)
zbm_require_bpool="only"
root="${root%!!}"
zbm_require_pool="only"
zbm_prefer_pool="${zbm_prefer_pool%!!}"
;;
*!)
zbm_require_bpool="yes"
root="${root%!}"
zbm_require_pool="yes"
zbm_prefer_pool="${zbm_prefer_pool%!}"
;;
*)
zbm_require_bpool=""
zbm_require_pool=""
;;
esac

# Make sure Dracut is happy that we have a root
if [ ${wait_for_zfs} -eq 1 ]; then
ln -s /dev/null /dev/root 2>/dev/null
fi

# shellcheck disable=SC2034
rootok=1
ln -s /dev/null /dev/root 2>/dev/null
4 changes: 2 additions & 2 deletions zfsbootmenu/pre-init/zfsbootmenu-preinit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export spl_hostid="${spl_hostid}"
export import_policy="${import_policy}"
export menu_timeout="${menu_timeout}"
export loglevel="${loglevel}"
export root="${root}"
export zbm_require_bpool="${zbm_require_bpool}"
export zbm_prefer_pool="${zbm_prefer_pool}"
export zbm_require_pool="${zbm_require_pool}"
export default_hostid=00bab10c
export zbm_sort="${zbm_sort}"
export zbm_set_hostid="${zbm_set_hostid}"
Expand Down

0 comments on commit 57b5572

Please sign in to comment.