代码拉取完成,页面将自动刷新
From ab04eb2f00bdc69fbd9ce91e83c7c0f909f3fbc7 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Mon, 30 Aug 2021 12:31:18 +0200
Subject: [PATCH 260/272] normal/main: Discover the device to read the config
from as a fallback
The GRUB core.img is generated locally, when this is done the grub2-probe
tool figures out the device and partition that needs to be read to parse
the GRUB configuration file.
But in some cases the core.img can't be generated on the host and instead
has to be done at package build time. For example, if needs to get signed
with a key that's only available on the package building infrastructure.
If that's the case, the prefix variable won't have a device and partition
but only a directory path. So there's no way for GRUB to know from which
device has to read the configuration file.
To allow GRUB to continue working on that scenario, fallback to iterating
over all the available devices, if reading the config failed when using
the prefix and fw_path variables.
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
grub-core/normal/main.c | 58 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 51 insertions(+), 7 deletions(-)
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index 668f48ba6..8e18dac0b 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -337,18 +337,13 @@ grub_enter_normal_mode (const char *config)
}
static grub_err_t
-grub_try_normal (const char *variable)
+grub_try_normal_prefix (const char *prefix)
{
char *config;
- const char *prefix;
grub_err_t err = GRUB_ERR_FILE_NOT_FOUND;
const char *net_search_cfg;
int disable_net_search = 0;
- prefix = grub_env_get (variable);
- if (!prefix)
- return GRUB_ERR_FILE_NOT_FOUND;
-
net_search_cfg = grub_env_get ("feature_net_search_cfg");
if (net_search_cfg && net_search_cfg[0] == 'n')
disable_net_search = 1;
@@ -362,7 +357,7 @@ grub_try_normal (const char *variable)
config = grub_malloc (config_len);
if (! config)
- return GRUB_ERR_FILE_NOT_FOUND;
+ return err;
grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
err = grub_net_search_config_file (config);
@@ -391,6 +386,53 @@ grub_try_normal (const char *variable)
return err;
}
+static int
+grub_try_normal_dev (const char *name, void *data)
+{
+ grub_err_t err;
+ const char *prefix = grub_xasprintf ("(%s)%s", name, (char *)data);
+
+ if (!prefix)
+ return 0;
+
+ err = grub_try_normal_prefix (prefix);
+ if (err == GRUB_ERR_NONE)
+ return 1;
+
+ return 0;
+}
+
+static grub_err_t
+grub_try_normal_discover (void)
+{
+ char *prefix = grub_env_get ("prefix");
+ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND;
+
+ if (!prefix)
+ return err;
+
+ if (grub_device_iterate (grub_try_normal_dev, (void *)prefix))
+ return GRUB_ERR_NONE;
+
+ return err;
+}
+
+static grub_err_t
+grub_try_normal (const char *variable)
+{
+ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND;
+ const char *prefix;
+
+ if (!variable)
+ return err;
+
+ prefix = grub_env_get (variable);
+ if (!prefix)
+ return err;
+
+ return grub_try_normal_prefix (prefix);
+}
+
/* Enter normal mode from rescue mode. */
static grub_err_t
grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
@@ -405,6 +447,8 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
err = grub_try_normal ("fw_path");
if (err == GRUB_ERR_FILE_NOT_FOUND)
err = grub_try_normal ("prefix");
+ if (err == GRUB_ERR_FILE_NOT_FOUND)
+ err = grub_try_normal_discover ();
if (err == GRUB_ERR_FILE_NOT_FOUND)
grub_enter_normal_mode (0);
}
--
2.41.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。