1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-25 23:21:33 +03:00

bootctl: add a convenient way to print the path to EFI

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2017-11-17 13:55:05 +01:00
parent 46fb255b0d
commit 30b5047762
2 changed files with 25 additions and 2 deletions

View File

@ -108,6 +108,14 @@
the ESP to <filename>/boot</filename>, if possible.</para></listitem> the ESP to <filename>/boot</filename>, if possible.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>-p</option></term>
<term><option>--print-path</option></term>
<listitem><para>This option modifies the behaviour of <command>status</command>.
Just print the path to the EFI System Partition (ESP) to standard output and
exit.</para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>--no-variables</option></term> <term><option>--no-variables</option></term>
<listitem><para>Do not touch the EFI boot variables.</para></listitem> <listitem><para>Do not touch the EFI boot variables.</para></listitem>

View File

@ -57,6 +57,7 @@
#include "virt.h" #include "virt.h"
static char *arg_path = NULL; static char *arg_path = NULL;
static bool arg_print_path = false;
static bool arg_touch_variables = true; static bool arg_touch_variables = true;
static int find_esp_and_warn(uint32_t *part, uint64_t *pstart, uint64_t *psize, sd_id128_t *uuid) { static int find_esp_and_warn(uint32_t *part, uint64_t *pstart, uint64_t *psize, sd_id128_t *uuid) {
@ -71,7 +72,7 @@ static int find_esp_and_warn(uint32_t *part, uint64_t *pstart, uint64_t *psize,
return log_error_errno(r, return log_error_errno(r,
"Couldn't find EFI system partition: %m"); "Couldn't find EFI system partition: %m");
log_info("Using EFI System Partition at %s.", arg_path); log_debug("Using EFI System Partition at %s.", arg_path);
return 0; return 0;
} }
@ -832,6 +833,7 @@ static int help(int argc, char *argv[], void *userdata) {
" -h --help Show this help\n" " -h --help Show this help\n"
" --version Print version\n" " --version Print version\n"
" --path=PATH Path to the EFI System Partition (ESP)\n" " --path=PATH Path to the EFI System Partition (ESP)\n"
" -p --print-path Print path to the EFI partition\n"
" --no-variables Don't touch EFI variables\n" " --no-variables Don't touch EFI variables\n"
"\n" "\n"
"Commands:\n" "Commands:\n"
@ -856,6 +858,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, ARG_VERSION }, { "version", no_argument, NULL, ARG_VERSION },
{ "path", required_argument, NULL, ARG_PATH }, { "path", required_argument, NULL, ARG_PATH },
{ "print-path", no_argument, NULL, 'p' },
{ "no-variables", no_argument, NULL, ARG_NO_VARIABLES }, { "no-variables", no_argument, NULL, ARG_NO_VARIABLES },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
@ -865,7 +868,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0); assert(argc >= 0);
assert(argv); assert(argv);
while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) while ((c = getopt_long(argc, argv, "hp", options, NULL)) >= 0)
switch (c) { switch (c) {
case 'h': case 'h':
@ -881,6 +884,10 @@ static int parse_argv(int argc, char *argv[]) {
return log_oom(); return log_oom();
break; break;
case 'p':
arg_print_path = true;
break;
case ARG_NO_VARIABLES: case ARG_NO_VARIABLES:
arg_touch_variables = false; arg_touch_variables = false;
break; break;
@ -919,6 +926,14 @@ static int verb_status(int argc, char *argv[], void *userdata) {
r = find_esp_and_warn(NULL, NULL, NULL, &uuid); r = find_esp_and_warn(NULL, NULL, NULL, &uuid);
if (arg_print_path) {
if (r < 0)
return r;
puts(arg_path);
return 0;
}
if (is_efi_boot()) { if (is_efi_boot()) {
_cleanup_free_ char *fw_type = NULL, *fw_info = NULL, *loader = NULL, *loader_path = NULL; _cleanup_free_ char *fw_type = NULL, *fw_info = NULL, *loader = NULL, *loader_path = NULL;
sd_id128_t loader_part_uuid = SD_ID128_NULL; sd_id128_t loader_part_uuid = SD_ID128_NULL;