From 9914d89b5162a7cd47ecb15e679b944d87fdf1e4 Mon Sep 17 00:00:00 2001 From: Goffredo Baroncelli Date: Tue, 18 Jan 2022 19:32:35 +0100 Subject: [PATCH 1/2] bootctl: ignore the bootloader boot entries When bootctl lists the boot entries, considers also the ones returned by systemd-boot (via the efi LoaderEntries variable), created at boot time. Unfortunately this list may became incorrect if (e.g.) the user remove a kernel package. This patch changes this behaviour, so bootctl ignores some the boot entries returned by systemd-boot. In any case, bootctl still considers the 'auto-xxx' boot entries listed below: Boot entrie name Title ----------------------------- ------------------------------ auto-osx macOS boot loader auto-windows Windows Boot Manager auto-efi-shell EFI Shell auto-efi-default EFI Default Loader auto-reboot-to-firmware-setup Reboot Into Firmware Interface The other entries that systemd-boot synthetizes (e.g. the ones loaded from /efi/loader/entries/) can be synthetized by bootctl too, so no information is lost. Signed-off-by: Goffredo Baroncelli --- src/boot/bootctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index 1bcb4d1689..c3c72e314c 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -1603,7 +1603,7 @@ static int verb_list(int argc, char *argv[], void *userdata) { else if (r < 0) log_warning_errno(r, "Failed to determine entries reported by boot loader, ignoring: %m"); else - (void) boot_entries_augment_from_loader(&config, efi_entries, false); + (void) boot_entries_augment_from_loader(&config, efi_entries, true); if (config.n_entries == 0) log_info("No boot loader entries found."); From 2fbf50d6750182d768de111cbd40eb9dd0f627af Mon Sep 17 00:00:00 2001 From: Goffredo Baroncelli Date: Tue, 18 Jan 2022 19:32:35 +0100 Subject: [PATCH 2/2] bootctl: removed unused parameter only_auto Remove the parameter 'only_auto' from the function boot_entries_augment_from_loader() because each caller set it always to true. Signed-off-by: Goffredo Baroncelli --- src/boot/bootctl.c | 2 +- src/login/logind-dbus.c | 4 ++-- src/shared/bootspec.c | 10 +++++++--- src/shared/bootspec.h | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index c3c72e314c..86391b8def 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -1603,7 +1603,7 @@ static int verb_list(int argc, char *argv[], void *userdata) { else if (r < 0) log_warning_errno(r, "Failed to determine entries reported by boot loader, ignoring: %m"); else - (void) boot_entries_augment_from_loader(&config, efi_entries, true); + (void) boot_entries_augment_from_loader(&config, efi_entries); if (config.n_entries == 0) log_info("No boot loader entries found."); diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index c05c0d02cc..f38f0629a8 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -3008,7 +3008,7 @@ static int boot_loader_entry_exists(Manager *m, const char *id) { r = manager_read_efi_boot_loader_entries(m); if (r >= 0) - (void) boot_entries_augment_from_loader(&config, m->efi_boot_loader_entries, true); + (void) boot_entries_augment_from_loader(&config, m->efi_boot_loader_entries); return boot_config_has_entry(&config, id); } @@ -3166,7 +3166,7 @@ static int property_get_boot_loader_entries( r = manager_read_efi_boot_loader_entries(m); if (r >= 0) - (void) boot_entries_augment_from_loader(&config, m->efi_boot_loader_entries, true); + (void) boot_entries_augment_from_loader(&config, m->efi_boot_loader_entries); r = sd_bus_message_open_container(reply, 'a', "s"); if (r < 0) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 0076092c2a..52268f6041 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -759,8 +759,7 @@ int boot_entries_load_config_auto( int boot_entries_augment_from_loader( BootConfig *config, - char **found_by_loader, - bool only_auto) { + char **found_by_loader) { static const char *const title_table[] = { /* Pretty names for a few well-known automatically discovered entries. */ @@ -785,7 +784,12 @@ int boot_entries_augment_from_loader( if (boot_config_has_entry(config, *i)) continue; - if (only_auto && !startswith(*i, "auto-")) + /* + * consider the 'auto-' entries only, because the others + * ones are detected scanning the 'esp' and 'xbootldr' + * directories by boot_entries_load_config() + */ + if (!startswith(*i, "auto-")) continue; c = strdup(*i); diff --git a/src/shared/bootspec.h b/src/shared/bootspec.h index 81845f47e3..4a95e24e27 100644 --- a/src/shared/bootspec.h +++ b/src/shared/bootspec.h @@ -76,7 +76,7 @@ static inline BootEntry* boot_config_default_entry(BootConfig *config) { void boot_config_free(BootConfig *config); int boot_entries_load_config(const char *esp_path, const char *xbootldr_path, BootConfig *config); int boot_entries_load_config_auto(const char *override_esp_path, const char *override_xbootldr_path, BootConfig *config); -int boot_entries_augment_from_loader(BootConfig *config, char **list, bool only_auto); +int boot_entries_augment_from_loader(BootConfig *config, char **list); static inline const char* boot_entry_title(const BootEntry *entry) { return entry->show_title ?: entry->title ?: entry->id;