grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Pascal Hambourg <pascal@plouf.fr.eu.org>
To: grub-devel@gnu.org
Subject: [PATCH v2] util/grub.d/30_os-prober.in: Conditionally show or hide chain and efi menu entries
Date: Fri, 19 Jan 2024 16:25:40 +0100	[thread overview]
Message-ID: <4afbf7da-3c13-4476-8c11-d762b477651c@plouf.fr.eu.org> (raw)

On systems which support multiple boot platforms such as BIOS or EFI,
it makes no sense to show menu entries which are not supported by
the current boot platform. Menu entries generated from os-prober
'chain' boot type use boot sector chainloading which is supported
by PC BIOS platform only.

Show 'chain' menu entries only if boot platform is PC BIOS.
Show 'efi' menu entries only if boot platform is EFI.

This is aimed to allow os-prober to report both EFI and PC BIOS
boot loaders regardless of the current boot mode on x86 systems
which support both EFI and legacy BIOS boot.

Signed-off-by: Pascal Hambourg <pascal@plouf.fr.eu.org>
---
Note: I did not change indentation to keep the patch minimal.

v2:
- show 'chain' menu entries if platform=pc instead of platform!=efi
- add explanatory comments in generated config

 util/grub.d/30_os-prober.in | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
index 043e5dfea..e9e217208 100644
--- a/util/grub.d/30_os-prober.in
+++ b/util/grub.d/30_os-prober.in
@@ -155,6 +155,8 @@ for OS in ${OSPROBED} ; do
 
 	  onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
       cat << EOF
+# this menu entry is supported only by PC BIOS platform
+if [ "\$grub_platform" = "pc" ]; then
 menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' $CLASS --class os \$menuentry_id_option 'osprober-chain-$(grub_get_device_id "${DEVICE}")' {
 EOF
       save_default_entry | grub_add_tab
@@ -179,6 +181,7 @@ EOF
       cat <<EOF
 	chainloader +1
 }
+fi
 EOF
     ;;
     efi)
@@ -187,6 +190,8 @@ EOF
 	DEVICE=${DEVICE%@*}
 	onstr="$(gettext_printf "(on %s)" "${DEVICE}")"
       cat << EOF
+# this menu entry is supported only by EFI platform
+if [ "\$grub_platform" = "efi" ]; then
 menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' $CLASS --class os \$menuentry_id_option 'osprober-efi-$(grub_get_device_id "${DEVICE}")' {
 EOF
       save_default_entry | sed -e "s/^/\t/"
@@ -195,6 +200,7 @@ EOF
       cat <<EOF
 	chainloader ${EFIPATH}
 }
+fi
 EOF
     ;;
     linux)
-- 
2.30.2

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

             reply	other threads:[~2024-01-19 15:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 15:25 Pascal Hambourg [this message]
2024-05-01 21:07 ` [PATCH v2] util/grub.d/30_os-prober.in: Conditionally show or hide chain and efi menu entries Pascal Hambourg

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=4afbf7da-3c13-4476-8c11-d762b477651c@plouf.fr.eu.org \
    --to=pascal@plouf.fr.eu.org \
    --cc=grub-devel@gnu.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).