All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix missing root pool in 10_linux
@ 2021-01-03  7:14 ja
  2021-01-03 14:45 ` [PATCH] Fix missing root pool in 10_linux: better wording; add intructions when fail gyc
  0 siblings, 1 reply; 4+ messages in thread
From: ja @ 2021-01-03  7:14 UTC (permalink / raw)
  To: grub-devel

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix missing root pool in 10_linux: better wording; add intructions when fail
  2021-01-03  7:14 [PATCH] Fix missing root pool in 10_linux ja
@ 2021-01-03 14:45 ` gyc
  2021-01-03 14:51   ` [PATCH] Fix missing root pool in 10_linux: successfully built GRUB with both patches on Arch Linux gyc
  2021-01-03 15:30   ` [PATCH] Fix missing root pool in 10_linux: remove duplicate word 'export' gyc
  0 siblings, 2 replies; 4+ messages in thread
From: gyc @ 2021-01-03 14:45 UTC (permalink / raw)
  To: The development of GNU GRUB

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(-)

diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index 04f8a11e6..2c3958ae1 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix missing root pool in 10_linux: successfully built GRUB with both patches on Arch Linux
  2021-01-03 14:45 ` [PATCH] Fix missing root pool in 10_linux: better wording; add intructions when fail gyc
@ 2021-01-03 14:51   ` gyc
  2021-01-03 15:30   ` [PATCH] Fix missing root pool in 10_linux: remove duplicate word 'export' gyc
  1 sibling, 0 replies; 4+ messages in thread
From: gyc @ 2021-01-03 14:51 UTC (permalink / raw)
  To: The development of GNU GRUB

Forgot to say, I've successfully built GRUB with both patches
applied on Arch Linux on commit
635ef55ed1252f92fe3bf70caefd185dcc507c43.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix missing root pool in 10_linux: remove duplicate word 'export'
  2021-01-03 14:45 ` [PATCH] Fix missing root pool in 10_linux: better wording; add intructions when fail gyc
  2021-01-03 14:51   ` [PATCH] Fix missing root pool in 10_linux: successfully built GRUB with both patches on Arch Linux gyc
@ 2021-01-03 15:30   ` gyc
  1 sibling, 0 replies; 4+ messages in thread
From: gyc @ 2021-01-03 15:30 UTC (permalink / raw)
  To: The development of GNU GRUB

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(-)

diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
index 2c3958ae1..fd021d52c 100644
--- a/util/grub-mkconfig.in
+++ b/util/grub-mkconfig.in
@@ -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
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-03 15:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-03  7:14 [PATCH] Fix missing root pool in 10_linux ja
2021-01-03 14:45 ` [PATCH] Fix missing root pool in 10_linux: better wording; add intructions when fail gyc
2021-01-03 14:51   ` [PATCH] Fix missing root pool in 10_linux: successfully built GRUB with both patches on Arch Linux gyc
2021-01-03 15:30   ` [PATCH] Fix missing root pool in 10_linux: remove duplicate word 'export' gyc

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.