From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kw0bh-0006aR-DH for mharc-grub-devel@gnu.org; Sun, 03 Jan 2021 05:27:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kvxbN-0001d4-R1 for grub-devel@gnu.org; Sun, 03 Jan 2021 02:14:58 -0500 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:55055) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kvxbK-00046z-C1 for grub-devel@gnu.org; Sun, 03 Jan 2021 02:14:57 -0500 X-Originating-IP: 112.41.129.199 Received: from yc-eb820g3 (unknown [112.41.129.199]) (Authenticated sender: gyc@apvc.uk) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 0D70760002 for ; Sun, 3 Jan 2021 07:14:47 +0000 (UTC) Date: Sun, 3 Jan 2021 15:14:39 +0800 From: ja@apvc.uk To: grub-devel@gnu.org Subject: [PATCH] Fix missing root pool in 10_linux Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Received-SPF: pass client-ip=217.70.183.195; envelope-from=ja@apvc.uk; helo=relay3-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 03 Jan 2021 05:27:28 -0500 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jan 2021 07:14:58 -0000 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 , 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 --- 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