diff --git a/zfsbootmenu/lib/zfsbootmenu-core.sh b/zfsbootmenu/lib/zfsbootmenu-core.sh index e165bf216..08b1de5bd 100755 --- a/zfsbootmenu/lib/zfsbootmenu-core.sh +++ b/zfsbootmenu/lib/zfsbootmenu-core.sh @@ -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 diff --git a/zfsbootmenu/libexec/zfsbootmenu-init b/zfsbootmenu/libexec/zfsbootmenu-init index 7b5f9814f..5631d280a 100755 --- a/zfsbootmenu/libexec/zfsbootmenu-init +++ b/zfsbootmenu/libexec/zfsbootmenu-init @@ -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 @@ -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 @@ -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="" @@ -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 )" @@ -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 diff --git a/zfsbootmenu/pre-init/zfsbootmenu-parse-commandline.sh b/zfsbootmenu/pre-init/zfsbootmenu-parse-commandline.sh index 9daddfda2..1954c67d8 100755 --- a/zfsbootmenu/pre-init/zfsbootmenu-parse-commandline.sh +++ b/zfsbootmenu/pre-init/zfsbootmenu-parse-commandline.sh @@ -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#\"}" @@ -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 diff --git a/zfsbootmenu/pre-init/zfsbootmenu-preinit.sh b/zfsbootmenu/pre-init/zfsbootmenu-preinit.sh index 79394b261..e6c0f3ebf 100755 --- a/zfsbootmenu/pre-init/zfsbootmenu-preinit.sh +++ b/zfsbootmenu/pre-init/zfsbootmenu-preinit.sh @@ -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}"