bootctl: show more information about boot entry state in list

Let's improve display of boot entries and show what type they have (i.e.
boot loader spec type 1, or type 2, or auto-discovered or reported by
boot loader), and in particular mark entries the boot loader discovered
but we can't find (i.e. that likely vanished, or possibly couldn't be
found due to a misconfiguration) and that the boot loader didn't find
but we see (which are new, or possibly also the result of
misconfiguraiton).

This is supposed to be a replacement for #22161, but instead of hiding
vanished entries, highlights them, which I think is more appropriate for
a low-level tool such bootctl.

Replaces: #22161 #22398
This commit is contained in:
Lennart Poettering
2022-02-14 15:44:07 +01:00
parent a78e472dfd
commit bb68205768
4 changed files with 75 additions and 29 deletions
+45 -9
View File
@@ -36,6 +36,7 @@
#include "rm-rf.h"
#include "stat-util.h"
#include "stdio-util.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
#include "sync-util.h"
@@ -411,10 +412,20 @@ static void boot_entry_file_list(const char *field, const char *root, const char
*ret_status = status;
}
static const char* const boot_entry_type_table[_BOOT_ENTRY_TYPE_MAX] = {
[BOOT_ENTRY_CONF] = "Boot Loader Specification Type #1 (.conf)",
[BOOT_ENTRY_UNIFIED] = "Boot Loader Specification Type #2 (.efi)",
[BOOT_ENTRY_LOADER] = "Reported by Boot Loader",
[BOOT_ENTRY_LOADER_AUTO] = "Automatic",
};
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_type, BootEntryType);
static int boot_entry_show(
const BootEntry *e,
bool show_as_default,
bool show_as_selected) {
bool show_as_selected,
bool show_reported) {
int status = 0;
@@ -423,10 +434,30 @@ static int boot_entry_show(
assert(e);
printf(" title: %s%s%s" "%s%s%s" "%s%s%s\n",
ansi_highlight(), boot_entry_title(e), ansi_normal(),
ansi_highlight_green(), show_as_default ? " (default)" : "", ansi_normal(),
ansi_highlight_magenta(), show_as_selected ? " (selected)" : "", ansi_normal());
printf(" type: %s\n",
boot_entry_type_to_string(e->type));
printf(" title: %s%s%s",
ansi_highlight(), boot_entry_title(e), ansi_normal());
if (show_as_default)
printf(" %s(default)%s",
ansi_highlight_green(), ansi_normal());
if (show_as_selected)
printf(" %s(selected)%s",
ansi_highlight_magenta(), ansi_normal());
if (show_reported) {
if (e->type == BOOT_ENTRY_LOADER)
printf(" %s(reported/absent)%s",
ansi_highlight_red(), ansi_normal());
else if (!e->reported_by_loader && e->type != BOOT_ENTRY_LOADER_AUTO)
printf(" %s(not reported/new)%s",
ansi_highlight_green(), ansi_normal());
}
putchar('\n');
if (e->id)
printf(" id: %s\n", e->id);
@@ -524,7 +555,11 @@ static int status_entries(
else {
printf("Default Boot Loader Entry:\n");
r = boot_entry_show(config.entries + config.default_entry, /* show_as_default= */ false, /* show_as_selected= */ false);
r = boot_entry_show(
config.entries + config.default_entry,
/* show_as_default= */ false,
/* show_as_selected= */ false,
/* show_discovered= */ false);
if (r > 0)
/* < 0 is already logged by the function itself, let's just emit an extra warning if
the default entry is broken */
@@ -1619,7 +1654,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, /* only_auto= */ false);
if (config.n_entries == 0)
log_info("No boot loader entries found.");
@@ -1631,8 +1666,9 @@ static int verb_list(int argc, char *argv[], void *userdata) {
for (size_t n = 0; n < config.n_entries; n++) {
r = boot_entry_show(
config.entries + n,
n == (size_t) config.default_entry,
n == (size_t) config.selected_entry);
/* show_as_default= */ n == (size_t) config.default_entry,
/* show_as_selected= */ n == (size_t) config.selected_entry,
/* show_discovered= */ true);
if (r < 0)
return r;