Fix missing root pool in 10_linux
PATCH 1/1 Fix missing root pool in 10_linux
GRUB does not support some new ZFS features. To work around
this, many installations, such as guides provided by OpenZFS, chose to create a feature-limited zpool mounted at /boot solely for GRUB. This allows GRUB to boot from ZFS while using unsupported features on root pool.
However, if the zpool at / has features that GRUB does not support, the root zpool name will be missing from LINUX_ROOT_DEVICE, resulting in `root=ZFS=[missing]/xyz'. This will leave the system in an unbootable state.
This patch will warn the user if root zpool name is missing and suggest the user to manually specify the correct value with GRUB_ZFS_ALT_RPOOL variable.
Unlike a previous patch <https://lists.gnu.org/archive/html/grub-devel/2020-12/msg00239.html>,
this patch allows user to choose the alternative method of detecting
root zpool, such as
export GRUB_ZFS_ALT_RPOOL="zdb -l \${GRUB_DEVICE} | grep -E '[[:blank:]]name' | cut -d\' -f 2"
export GRUB_ZFS_ALT_RPOOL='blkid -s LABEL -o value ${GRUB_DEVICE}'Note that `${GRUB_DEVICE}' must be supplied as literal string.
--- util/grub-mkconfig.in | 12 +++++++++++- util/grub.d/10_linux.in | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-)
util/grub-mkconfig.in +11 -1
@@ -248,7 +248,8 @@ export GRUB_DEFAULT \ GRUB_ENABLE_CRYPTODISK \ GRUB_BADRAM \ GRUB_OS_PROBER_SKIP_LIST \ - GRUB_DISABLE_SUBMENU + GRUB_DISABLE_SUBMENU \ + GRUB_ZFS_ALT_RPOOL if test "x${grub_cfg}" != "x"; then rm -f "${grub_cfg}.new"
@@ -287,6 +288,15 @@ for i in "${grub_mkconfig_dir}"/* ; do done if test "x${grub_cfg}" != "x" ; then + if test "x${GRUB_FS}" = "xzfs" ; then + if grep -q "grub_root_pool_detection_failed" ${grub_cfg}.new ; then + gettext_printf "Root pool detection failed! +You must specify correct pool name with GRUB_ZFS_ALT_RPOOL +and run the command again. Otherwise system will not boot." >&2 + echo >&2 + exit 1 + fi + fi if ! ${grub_script_check} ${grub_cfg}.new; then # TRANSLATORS: %s is replaced by filename gettext_printf "Syntax errors are detected in generated GRUB config file.
util/grub.d/10_linux.in +1 -1
@@ -71,7 +71,7 @@ case x"$GRUB_FS" in GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" fi;; xzfs) - rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` + rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || test -n "${GRUB_ZFS_ALT_RPOOL}" && eval "${GRUB_ZFS_ALT_RPOOL}" || echo "grub_root_pool_detection_failed"` bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`" LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}" ;;
--
2.30.0
Re: [PATCH] Fix missing root pool in 10_linux: better wording; add intructions when fail
After applying the previous patch, apply this patch to show recovery instructions when root pool detection fails. Also the description has been improved.
This could be very useful guiding people to fix failed root pool detection.
--- util/grub-mkconfig.in | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
util/grub-mkconfig.in +15 -2
@@ -291,8 +291,21 @@ if test "x${grub_cfg}" != "x" ; then if test "x${GRUB_FS}" = "xzfs" ; then if grep -q "grub_root_pool_detection_failed" ${grub_cfg}.new ; then gettext_printf "Root pool detection failed! -You must specify correct pool name with GRUB_ZFS_ALT_RPOOL -and run the command again. Otherwise system will not boot." >&2 +You must specify pool name detection command with GRUB_ZFS_ALT_RPOOL +and run the command again. Otherwise system will not boot. + +Possible detection commands: + +with zdb + if + zdb -l %s | grep -E '[[:blank:]]name' | cut -d\\\' -f 2 + returns root pool name, then try set + export GRUB_ZFS_ALT_RPOOL=\"zdb -l \\\${GRUB_DEVICE} | grep -E '[[:blank:]]name' | cut -d\\\' -f 2\" +with blkid + if + blkid -s LABEL -o value %s + returns root pool name, then try set + export export GRUB_ZFS_ALT_RPOOL='blkid -s LABEL -o value \${GRUB_DEVICE}'" "${GRUB_DEVICE}" "${GRUB_DEVICE}" >&2 echo >&2 exit 1 fi
--
2.30.0
Re: [PATCH] Fix missing root pool in 10_linux: successfully built GRUB with both patches on Arch Linux
Forgot to say, I've successfully built GRUB with both patches applied on Arch Linux on commit 635ef55ed1252f92fe3bf70caefd185dcc507c43.
Re: [PATCH] Fix missing root pool in 10_linux: remove duplicate word 'export'
In reply to [email protected]This patch removes duplicate word 'export' in 'Re: [PATCH] Fix missing root pool in 10_linux: better wording; add intru'
--- util/grub-mkconfig.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/grub-mkconfig.in +1 -1
@@ -305,7 +305,7 @@ with blkid if blkid -s LABEL -o value %s returns root pool name, then try set - export export GRUB_ZFS_ALT_RPOOL='blkid -s LABEL -o value \${GRUB_DEVICE}'" "${GRUB_DEVICE}" "${GRUB_DEVICE}" >&2 + export GRUB_ZFS_ALT_RPOOL='blkid -s LABEL -o value \${GRUB_DEVICE}'" "${GRUB_DEVICE}" "${GRUB_DEVICE}" >&2 echo >&2 exit 1 fi
Signature · 1 line
2.30.0