grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix missing root pool in 10_linux


From: ja
Subject: [PATCH] Fix missing root pool in 10_linux
Date: Sun, 3 Jan 2021 15:14:39 +0800

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.

Signed-off-by: Maurice Zhou <ja@apvc.uk>
---
 util/grub-mkconfig.in   | 12 +++++++++++-
 util/grub.d/10_linux.in |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index d3e879b8e..04f8a11e6 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -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.
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index e8b01c0d0..5d84f5bb4 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]