!368 [sync] PR-366: look for grub.cfg on efi where the app was found

From: @openeuler-sync-bot 
Reviewed-by: @zhangqiumiao 
Signed-off-by: @zhangqiumiao
This commit is contained in:
openeuler-ci-bot 2024-03-15 06:17:15 +00:00 committed by Gitee
commit 6946a73eb4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 131 additions and 1 deletions

View File

@ -0,0 +1,81 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Date: Wed, 19 Sep 2012 21:22:55 -0300
Subject: [PATCH] Add fw_path variable (revised)
This patch makes grub look for its config file on efi where the app was
found. It was originally written by Matthew Garrett, and adapted to fix the
"No modules are loaded on grub2 network boot" issue:
https://bugzilla.redhat.com/show_bug.cgi?id=857936
Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
---
grub-core/kern/main.c | 13 ++++++-------
grub-core/normal/main.c | 25 ++++++++++++++++++++++++-
2 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
index 73967e2f5b0..d1de9fa6873 100644
--- a/grub-core/kern/main.c
+++ b/grub-core/kern/main.c
@@ -128,16 +128,15 @@ grub_set_prefix_and_root (void)
grub_machine_get_bootlocation (&fwdevice, &fwpath);
- if (fwdevice)
+ if (fwdevice && fwpath)
{
- char *cmdpath;
+ char *fw_path;
- cmdpath = grub_xasprintf ("(%s)%s", fwdevice, fwpath ? : "");
- if (cmdpath)
+ fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
+ if (fw_path)
{
- grub_env_set ("cmdpath", cmdpath);
- grub_env_export ("cmdpath");
- grub_free (cmdpath);
+ grub_env_set ("fw_path", fw_path);
+ grub_free (fw_path);
}
}
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index 70614de1565..62571e6dfcc 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -339,7 +339,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
/* Guess the config filename. It is necessary to make CONFIG static,
so that it won't get broken by longjmp. */
char *config;
- const char *prefix;
+ const char *prefix, *fw_path;
+
+ fw_path = grub_env_get ("fw_path");
+ if (fw_path)
+ {
+ config = grub_xasprintf ("%s/grub.cfg", fw_path);
+ if (config)
+ {
+ grub_file_t file;
+
+ file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
+ if (file)
+ {
+ grub_file_close (file);
+ grub_enter_normal_mode (config);
+ }
+ else
+ {
+ /* Ignore all errors. */
+ grub_errno = 0;
+ }
+ grub_free (config);
+ }
+ }
prefix = grub_env_get ("prefix");
if (prefix)

View File

@ -0,0 +1,41 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Fedora Ninjas <grub2-owner@fedoraproject.org>
Date: Wed, 19 Feb 2014 15:58:43 -0500
Subject: [PATCH] use fw_path prefix when fallback searching for grub config
When PXE booting via UEFI firmware, grub was searching for grub.cfg
in the fw_path directory where the grub application was found. If
that didn't exist, a fallback search would look for config file names
based on MAC and IP address. However, the search would look in the
prefix directory which may not be the same fw_path. This patch
changes that behavior to use the fw_path directory for the fallback
search. Only if fw_path is NULL will the prefix directory be searched.
Signed-off-by: Mark Salter <msalter@redhat.com>
---
grub-core/normal/main.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index 7ca2e5400b1..02577502116 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -347,7 +347,7 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
char *config;
const char *prefix, *fw_path;
- fw_path = grub_env_get ("fw_path");
+ prefix = fw_path = grub_env_get ("fw_path");
if (fw_path)
{
config = grub_xasprintf ("%s/grub.cfg", fw_path);
@@ -370,7 +370,8 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
}
}
- prefix = grub_env_get ("prefix");
+ if (! prefix)
+ prefix = grub_env_get ("prefix");
if (prefix)
{
grub_size_t config_len;

View File

@ -206,5 +206,7 @@ Patch205: disable-some-unsupported-filesystems.patch
Patch206: remove-the-items-of-unsupported-filesystems-in-fs.ls.patch Patch206: remove-the-items-of-unsupported-filesystems-in-fs.ls.patch
Patch207: backport-Read-etc-default-grub.d-.cfg-after-etc-default-grub.patch Patch207: backport-Read-etc-default-grub.d-.cfg-after-etc-default-grub.patch
Patch208: modify-klist-in-10_linux.in.patch Patch208: modify-klist-in-10_linux.in.patch
Patch209: 0019-Add-fw_path-variable-revised.patch
Patch210: 0028-use-fw_path-prefix-when-fallback-searching-for-grub-.patch
#Patch208: add-TPCM-support-with-ipmi-channel.patch #Patch208: add-TPCM-support-with-ipmi-channel.patch
#Patch209: skip-verification-when-not-loading-grub.cfg.patch #Patch209: skip-verification-when-not-loading-grub.cfg.patch

View File

@ -14,7 +14,7 @@
Name: grub2 Name: grub2
Epoch: 1 Epoch: 1
Version: 2.12 Version: 2.12
Release: 2 Release: 3
Summary: Bootloader with support for Linux, Multiboot and more Summary: Bootloader with support for Linux, Multiboot and more
License: GPLv3+ License: GPLv3+
URL: http://www.gnu.org/software/grub/ URL: http://www.gnu.org/software/grub/
@ -449,6 +449,12 @@ fi
%{_datadir}/man/man* %{_datadir}/man/man*
%changelog %changelog
* Fri Mar 8 2024 zhangqiumiao <zhangqiumiao1@huawei.com> - 1:2.12-3
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:look for grub.cfg on efi where the app was found
* Thu Mar 7 2024 zhangqiumiao <zhangqiumiao1@huawei.com> - 1:2.12-2 * Thu Mar 7 2024 zhangqiumiao <zhangqiumiao1@huawei.com> - 1:2.12-2
- Type:bugfix - Type:bugfix
- CVE:NA - CVE:NA