From: Michael Chang via Grub-devel <grub-devel@gnu.org>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: Michael Chang <mchang@suse.com>, Neal Gompa <ngompa13@gmail.com>,
Marta Lewandowska <mlewando@redhat.com>
Subject: [PATCH v2 8/9] 00_header.in: wire grub.cfg to use env_block when present
Date: Mon, 15 Sep 2025 17:08:47 +0800 [thread overview]
Message-ID: <20250915090848.131937-9-mchang@suse.com> (raw)
In-Reply-To: <20250915090848.131937-1-mchang@suse.com>
This patch extends the generated grub.cfg so that it can use the
external environment block when the variable env_block is defined.
During boot, if env_block is set, grub.cfg builds a device path for it,
exports the variable, and then loads its contents in addition to the
normal grubenv file.
When GRUB writes variables such as next_entry or saved_entry, the save
commands are changed to write into env_block if it is set, and to fall
back to the grubenv file otherwise. In this way the external environment
block is used automatically, and existing commands like savedefault or
save_env do not need to change.
Signed-off-by: Michael Chang <mchang@suse.com>
---
| 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
--git a/util/grub.d/00_header.in b/util/grub.d/00_header.in
index f86b69bad..9d36feda3 100644
--- a/util/grub.d/00_header.in
+++ b/util/grub.d/00_header.in
@@ -46,6 +46,13 @@ cat << EOF
if [ -s \$prefix/grubenv ]; then
load_env
fi
+
+if [ "\${env_block}" ] ; then
+ set env_block="(\${root})\${env_block}"
+ export env_block
+ load_env -f "\${env_block}"
+fi
+
EOF
if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
cat <<EOF
@@ -54,7 +61,11 @@ if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
elif [ "\${next_entry}" ] ; then
set default="\${next_entry}"
set next_entry=
- save_env next_entry
+ if [ "\${env_block}" ] ; then
+ save_env -f "\${env_block}" next_entry
+ else
+ save_env next_entry
+ fi
set boot_once=true
else
set default="${GRUB_DEFAULT}"
@@ -65,7 +76,11 @@ else
if [ "\${next_entry}" ] ; then
set default="\${next_entry}"
set next_entry=
- save_env next_entry
+ if [ "\${env_block}" ] ; then
+ save_env -f "\${env_block}" next_entry
+ else
+ save_env next_entry
+ fi
set boot_once=true
else
set default="${GRUB_DEFAULT}"
@@ -93,7 +108,12 @@ fi
function savedefault {
if [ -z "\${boot_once}" ]; then
saved_entry="\${chosen}"
- save_env saved_entry
+ if [ "\${env_block}" ] ; then
+ save_env -f "\${env_block}" saved_entry
+ else
+ save_env saved_entry
+ fi
+
fi
}
--
2.51.0
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next prev parent reply other threads:[~2025-09-15 9:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-15 9:08 [PATCH v2 0/9] Add support for external environment block on Btrfs Michael Chang via Grub-devel
2025-09-15 9:08 ` [PATCH v2 1/9] util/grub-editenv: add basic structures and probe call for external envblk Michael Chang via Grub-devel
2025-09-15 9:08 ` [PATCH v2 2/9] util/grub-editenv: add fs_envblk open helper Michael Chang via Grub-devel
2025-09-15 9:08 ` [PATCH v2 3/9] util/grub-editenv: add fs_envblk write helper Michael Chang via Grub-devel
2025-09-15 9:08 ` [PATCH v2 4/9] util/grub-editenv: wire set_variables to optional fs_envblk Michael Chang via Grub-devel
2025-09-15 9:08 ` [PATCH v2 5/9] util/grub-editenv: wire unset_variables " Michael Chang via Grub-devel
2025-09-15 9:08 ` [PATCH v2 6/9] util/grub-editenv: wire list_variables " Michael Chang via Grub-devel
2025-09-17 15:16 ` Sudhakar Kuppusamy
2025-09-15 9:08 ` [PATCH v2 7/9] btrfs: add environment block to reserved header area Michael Chang via Grub-devel
2025-09-15 9:08 ` Michael Chang via Grub-devel [this message]
2025-09-15 9:08 ` [PATCH v2 9/9] docs: add Btrfs env block and special env vars Michael Chang via Grub-devel
2025-09-16 12:05 ` [PATCH v2 0/9] Add support for external environment block on Btrfs Neal Gompa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250915090848.131937-9-mchang@suse.com \
--to=grub-devel@gnu.org \
--cc=mchang@suse.com \
--cc=mlewando@redhat.com \
--cc=ngompa13@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).