Skip to content

Commit

Permalink
Add --efi-label argument to bootctl to control the name of the boot
Browse files Browse the repository at this point in the history
entry.

By default an entry named "Linux Boot Manager" is created (which is the
previous behavior). With the flag the name of the entry can be
controlled, which is useful when installing systemd-boot to multiple ESP
partitions and having uniquely named entries.

Fixes systemd#17044.
  • Loading branch information
ReneHollander committed Aug 13, 2022
1 parent 38db7a4 commit 02df056
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions man/bootctl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@
<listitem><para>Install binaries for all supported EFI architectures (this implies <option>--no-variables</option>).</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--efi-label=</option></term>
<listitem><para>Name of the entry added to the firmware's boot loader list. Defaults to <literal>Linux
Boot Manager</literal>.</para></listitem>
</varlistentry>

<xi:include href="standard-options.xml" xpointer="no-pager"/>
<xi:include href="standard-options.xml" xpointer="json" />
<xi:include href="standard-options.xml" xpointer="help"/>
Expand Down
26 changes: 24 additions & 2 deletions src/boot/bootctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ static enum {
ARG_INSTALL_SOURCE_HOST,
ARG_INSTALL_SOURCE_AUTO,
} arg_install_source = ARG_INSTALL_SOURCE_AUTO;
static char *arg_efi_label = NULL;

STATIC_DESTRUCTOR_REGISTER(arg_esp_path, freep);
STATIC_DESTRUCTOR_REGISTER(arg_xbootldr_path, freep);
STATIC_DESTRUCTOR_REGISTER(arg_install_layout, freep);
STATIC_DESTRUCTOR_REGISTER(arg_entry_token, freep);
STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
STATIC_DESTRUCTOR_REGISTER(arg_efi_label, freep);

static const char *arg_dollar_boot_path(void) {
/* $BOOT shall be the XBOOTLDR partition if it exists, and otherwise the ESP */
Expand Down Expand Up @@ -1139,13 +1141,13 @@ static int install_variables(const char *esp_path,
"Failed to determine current boot order: %m");

if (first || r == 0) {
r = efi_add_boot_option(slot, "Linux Boot Manager",
r = efi_add_boot_option(slot, arg_efi_label ?: "Linux Boot Manager",
part, pstart, psize,
uuid, path);
if (r < 0)
return log_error_errno(r, "Failed to create EFI Boot variable entry: %m");

log_info("Created EFI boot entry \"Linux Boot Manager\".");
log_info("Created EFI boot entry \"%s\".", arg_efi_label ?: "Linux Boot Manager");
}

return insert_into_order(slot, first);
Expand Down Expand Up @@ -1465,6 +1467,8 @@ static int help(int argc, char *argv[], void *userdata) {
" Generate JSON output\n"
" --all-architectures\n"
" Install all supported EFI architectures\n"
" --efi-label=LABEL\n"
" Name of the boot loader entry\n"
"\nSee the %2$s for details.\n",
program_invocation_short_name,
link,
Expand All @@ -1491,6 +1495,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_ENTRY_TOKEN,
ARG_JSON,
ARG_ARCH_ALL,
ARG_EFI_LABEL,
};

static const struct option options[] = {
Expand All @@ -1514,6 +1519,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "entry-token", required_argument, NULL, ARG_ENTRY_TOKEN },
{ "json", required_argument, NULL, ARG_JSON },
{ "all-architectures", no_argument, NULL, ARG_ARCH_ALL },
{ "efi-label", required_argument, NULL, ARG_EFI_LABEL },
{}
};

Expand Down Expand Up @@ -1647,6 +1653,22 @@ static int parse_argv(int argc, char *argv[]) {
arg_arch_all = true;
break;

case ARG_EFI_LABEL:
if (isempty(optarg) || !string_is_safe(optarg)) {
_cleanup_free_ char *escaped = NULL;

escaped = cescape(optarg);
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Invalid --efi-label=: %s", strna(escaped));
}
if (strlen(optarg) > 1024)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--efi-label= too long: %zu > 1024", strlen(optarg));
r = free_and_strdup(&arg_efi_label, optarg);
if (r < 0)
return log_oom();
break;

case '?':
return -EINVAL;

Expand Down

0 comments on commit 02df056

Please sign in to comment.