1 Star 0 Fork 50

yangqiming/grub2_3

forked from src-anolis-os/grub2 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0160-Use-boot-loader-entries-as-BLS-directory-path-also-o.patch 5.02 KB
一键复制 编辑 原始数据 按行查看 历史
geliwei 提交于 2022-04-13 15:15 . update to grub2-2.02-120.el8.src.rpm
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Mon, 25 Jun 2018 11:45:33 +0200
Subject: [PATCH] Use /boot/loader/entries as BLS directory path also on EFI
systems
For EFI systems, the BLS fragments were stored in the EFI System Partition
(ESP) while in non-EFI systems it was stored in /boot.
For consistency, it's better to always store the BLS fragments in the same
path regardless of the firmware interface used.
Also change the grub2-switch-to-blscfg script default BLS directory.
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
grub-core/commands/blscfg.c | 48 ++++++++++++++++++++++++++++++++-----------
util/grub-switch-to-blscfg.in | 4 ++--
2 files changed, 38 insertions(+), 14 deletions(-)
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
index 831cdcacc..70939a818 100644
--- a/grub-core/commands/blscfg.c
+++ b/grub-core/commands/blscfg.c
@@ -381,9 +381,14 @@ static int bls_cmp(const void *p0, const void *p1, void *state UNUSED)
return rc;
}
+struct read_entry_info {
+ const char *devid;
+ const char *dirname;
+};
+
static int read_entry (
const char *filename,
- const struct grub_dirhook_info *info UNUSED,
+ const struct grub_dirhook_info *dirhook_info UNUSED,
void *data)
{
grub_size_t n;
@@ -391,8 +396,7 @@ static int read_entry (
grub_file_t f = NULL;
grub_off_t sz;
struct bls_entry *entry;
- const char *dirname= (const char *)data;
- const char *devid = grub_env_get ("boot");
+ struct read_entry_info *info = (struct read_entry_info *)data;
grub_dprintf ("blscfg", "filename: \"%s\"\n", filename);
@@ -406,7 +410,7 @@ static int read_entry (
if (grub_strcmp (filename + n - 5, ".conf") != 0)
return 0;
- p = grub_xasprintf ("(%s)%s/%s", devid, dirname, filename);
+ p = grub_xasprintf ("(%s)%s/%s", info->devid, info->dirname, filename);
f = grub_file_open (p);
if (!f)
@@ -655,10 +659,13 @@ static int find_entry (const char *filename,
void *data)
{
struct find_entry_info *info = (struct find_entry_info *)data;
+ struct read_entry_info read_entry_info;
grub_file_t f = NULL;
char *grubenv_path = NULL;
grub_envblk_t env = NULL;
char *default_blsdir = NULL;
+ grub_fs_t blsdir_fs = NULL;
+ grub_device_t blsdir_dev = NULL;
const char *blsdir = NULL;
char *saved_env_buf = NULL;
int r = 0;
@@ -678,9 +685,6 @@ static int find_entry (const char *filename,
if (info->platform == PLATFORM_EMU)
default_blsdir = grub_xasprintf ("%s%s", GRUB_BOOT_DEVICE,
GRUB_BLS_CONFIG_PATH);
- else if (info->platform == PLATFORM_EFI)
- default_blsdir = grub_xasprintf ("/EFI/%s%s", filename,
- GRUB_BLS_CONFIG_PATH);
else
default_blsdir = grub_xasprintf ("%s", GRUB_BLS_CONFIG_PATH);
@@ -744,16 +748,33 @@ static int find_entry (const char *filename,
goto finish;
grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir);
- if (blsdir[0] != '/' && info->platform == PLATFORM_EFI)
- blsdir = grub_xasprintf ("/EFI/%s/%s/", filename, blsdir);
- else
- blsdir = grub_strdup (blsdir);
+ blsdir = grub_strdup (blsdir);
if (!blsdir)
goto finish;
grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir);
- r = info->fs->dir (info->dev, blsdir, read_entry, (char *)blsdir);
+ if (info->platform == PLATFORM_EFI) {
+ read_entry_info.devid = grub_env_get ("root");
+ if (!read_entry_info.devid)
+ goto finish;
+
+ blsdir_dev = grub_device_open (read_entry_info.devid);
+ if (!blsdir_dev)
+ goto finish;
+
+ blsdir_fs = grub_fs_probe (blsdir_dev);
+ if (!blsdir_fs)
+ goto finish;
+
+ } else {
+ read_entry_info.devid = devid;
+ blsdir_dev = info->dev;
+ blsdir_fs = info->fs;
+ }
+ read_entry_info.dirname = blsdir;
+
+ r = blsdir_fs->dir (blsdir_dev, blsdir, read_entry, &read_entry_info);
if (r != 0) {
grub_dprintf ("blscfg", "read_entry returned error\n");
grub_err_t e;
@@ -773,6 +794,9 @@ static int find_entry (const char *filename,
for (r = 0; r < nentries; r++)
bls_free_entry (entries[r]);
finish:
+ if (info->platform == PLATFORM_EFI && blsdir_dev)
+ grub_device_close (blsdir_dev);
+
nentries = 0;
grub_free (entries);
diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in
index 884cf45b1..2f37a1f74 100644
--- a/util/grub-switch-to-blscfg.in
+++ b/util/grub-switch-to-blscfg.in
@@ -44,13 +44,13 @@ EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/')
if [ -d /sys/firmware/efi/efivars/ ]; then
startlink=/etc/grub2-efi.cfg
grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'`
- blsdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/loader/entries" | sed 's,//*,/,g'`
else
startlink=/etc/grub2.cfg
grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
- blsdir=`echo "/@bootdirname@/loader/entries" | sed 's,//*,/,g'`
fi
+blsdir=`echo "/@bootdirname@/loader/entries" | sed 's,//*,/,g'`
+
backupsuffix=.bak
export TEXTDOMAIN=@PACKAGE@
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yyangqiming/grub2_3.git
git@gitee.com:yyangqiming/grub2_3.git
yyangqiming
grub2_3
grub2_3
a8

搜索帮助