From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Wed, 18 Jul 2018 08:08:06 +0200
Subject: [PATCH] blscfg: Fallback to search BLS snippets in
/boot/loader/entries
The default path to search the BLS snippets is /loader/entries, this is
only a correct assumption if $root ($root) is a boot partition but it's
not true if /boot isn't a mount point.
A user can set a blsdir grub environment variable to choose a different
path, but instead of failing when /boot is a directory inside the root
partition fallback to search the BLS in /boot/loader/entries to cover
that case as well.
Reported-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
grub-core/commands/blscfg.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
index 80d8814fc3f..321c93069f2 100644
--- a/grub-core/commands/blscfg.c
+++ b/grub-core/commands/blscfg.c
@@ -692,6 +692,7 @@ static int find_entry (const char *filename,
grub_device_t blsdir_dev = NULL;
const char *blsdir = NULL;
char *saved_env_buf = NULL;
+ int fallback = 0;
int r = 0;
const char *devid = grub_env_get ("boot");
@@ -797,7 +798,9 @@ static int find_entry (const char *filename,
}
read_entry_info.dirname = blsdir;
- r = blsdir_fs->dir (blsdir_dev, blsdir, read_entry, &read_entry_info);
+read_fallback:
+ r = blsdir_fs->dir (blsdir_dev, read_entry_info.dirname, read_entry,
+ &read_entry_info);
if (r != 0) {
grub_dprintf ("blscfg", "read_entry returned error\n");
grub_err_t e;
@@ -807,6 +810,14 @@ static int find_entry (const char *filename,
} while (e);
}
+ if (!nentries && !fallback && info->platform != PLATFORM_EMU) {
+ read_entry_info.dirname = "/boot" GRUB_BLS_CONFIG_PATH;
+ grub_dprintf ("blscfg", "Entries weren't found in %s, fallback to %s\n",
+ blsdir, read_entry_info.dirname);
+ fallback = 1;
+ goto read_fallback;
+ }
+
grub_dprintf ("blscfg", "Sorting %d entries\n", nentries);
grub_qsort(&entries[0], nentries, sizeof (struct bls_entry *), bls_cmp, NULL);