1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 #include <linux/magic.h>
17 #include <sys/statfs.h>
22 #include "alloc-util.h"
23 #include "blkid-util.h"
26 #include "dirent-util.h"
31 #include "locale-util.h"
32 #include "parse-util.h"
34 #include "stat-util.h"
35 #include "string-util.h"
37 #include "terminal-util.h"
38 #include "umask-util.h"
43 static char *arg_path
= NULL
;
44 static bool arg_print_path
= false;
45 static bool arg_touch_variables
= true;
47 static int acquire_esp(
48 bool unprivileged_mode
,
52 sd_id128_t
*ret_uuid
) {
57 /* Find the ESP, and log about errors. Note that find_esp_and_warn() will log in all error cases on its own,
58 * except for ENOKEY (which is good, we want to show our own message in that case, suggesting use of --path=)
59 * and EACCESS (only when we request unprivileged mode; in this case we simply eat up the error here, so that
60 * --list and --status work too, without noise about this). */
62 r
= find_esp_and_warn(arg_path
, unprivileged_mode
, &np
, ret_part
, ret_pstart
, ret_psize
, ret_uuid
);
64 return log_error_errno(r
,
65 "Couldn't find EFI system partition. It is recommended to mount it to /boot or /efi.\n"
66 "Alternatively, use --path= to specify path to mount point.");
70 free_and_replace(arg_path
, np
);
72 log_debug("Using EFI System Partition at %s.", arg_path
);
77 /* search for "#### LoaderInfo: systemd-boot 218 ####" string inside the binary */
78 static int get_file_version(int fd
, char **v
) {
88 if (fstat(fd
, &st
) < 0)
89 return log_error_errno(errno
, "Failed to stat EFI binary: %m");
91 if (st
.st_size
< 27) {
96 buf
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
97 if (buf
== MAP_FAILED
)
98 return log_error_errno(errno
, "Failed to memory map EFI binary: %m");
100 s
= memmem(buf
, st
.st_size
- 8, "#### LoaderInfo: ", 17);
105 e
= memmem(s
, st
.st_size
- (s
- buf
), " ####", 5);
106 if (!e
|| e
- s
< 3) {
107 log_error("Malformed version string.");
112 x
= strndup(s
, e
- s
);
120 (void) munmap(buf
, st
.st_size
);
125 static int enumerate_binaries(const char *esp_path
, const char *path
, const char *prefix
) {
127 _cleanup_closedir_
DIR *d
= NULL
;
131 p
= strjoina(esp_path
, "/", path
);
137 return log_error_errno(errno
, "Failed to read \"%s\": %m", p
);
140 FOREACH_DIRENT(de
, d
, break) {
141 _cleanup_close_
int fd
= -1;
142 _cleanup_free_
char *v
= NULL
;
144 if (!endswith_no_case(de
->d_name
, ".efi"))
147 if (prefix
&& !startswith_no_case(de
->d_name
, prefix
))
150 fd
= openat(dirfd(d
), de
->d_name
, O_RDONLY
|O_CLOEXEC
);
152 return log_error_errno(errno
, "Failed to open \"%s/%s\" for reading: %m", p
, de
->d_name
);
154 r
= get_file_version(fd
, &v
);
158 printf(" File: %s/%s/%s (%s)\n", special_glyph(TREE_RIGHT
), path
, de
->d_name
, v
);
160 printf(" File: %s/%s/%s\n", special_glyph(TREE_RIGHT
), path
, de
->d_name
);
167 static int status_binaries(const char *esp_path
, sd_id128_t partition
) {
170 printf("Boot Loader Binaries:\n");
173 printf(" ESP: Cannot find or access mount point of ESP.\n\n");
177 printf(" ESP: %s", esp_path
);
178 if (!sd_id128_is_null(partition
))
179 printf(" (/dev/disk/by-partuuid/%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x)", SD_ID128_FORMAT_VAL(partition
));
182 r
= enumerate_binaries(esp_path
, "EFI/systemd", NULL
);
184 log_error("systemd-boot not installed in ESP.");
188 r
= enumerate_binaries(esp_path
, "EFI/BOOT", "boot");
190 log_error("No default/fallback boot loader installed in ESP.");
199 static int print_efi_option(uint16_t id
, bool in_order
) {
200 _cleanup_free_
char *title
= NULL
;
201 _cleanup_free_
char *path
= NULL
;
202 sd_id128_t partition
;
206 r
= efi_get_boot_option(id
, &title
, &partition
, &path
, &active
);
210 /* print only configured entries with partition information */
211 if (!path
|| sd_id128_is_null(partition
))
214 efi_tilt_backslashes(path
);
216 printf(" Title: %s\n", strna(title
));
217 printf(" ID: 0x%04X\n", id
);
218 printf(" Status: %sactive%s\n", active
? "" : "in", in_order
? ", boot-order" : "");
219 printf(" Partition: /dev/disk/by-partuuid/%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n", SD_ID128_FORMAT_VAL(partition
));
220 printf(" File: %s%s\n", special_glyph(TREE_RIGHT
), path
);
226 static int status_variables(void) {
227 int n_options
, n_order
;
228 _cleanup_free_
uint16_t *options
= NULL
, *order
= NULL
;
231 n_options
= efi_get_boot_options(&options
);
232 if (n_options
== -ENOENT
)
233 return log_error_errno(n_options
,
234 "Failed to access EFI variables, efivarfs"
235 " needs to be available at /sys/firmware/efi/efivars/.");
237 return log_error_errno(n_options
, "Failed to read EFI boot entries: %m");
239 n_order
= efi_get_boot_order(&order
);
240 if (n_order
== -ENOENT
)
242 else if (n_order
< 0)
243 return log_error_errno(n_order
, "Failed to read EFI boot order.");
245 /* print entries in BootOrder first */
246 printf("Boot Loader Entries in EFI Variables:\n");
247 for (i
= 0; i
< n_order
; i
++)
248 print_efi_option(order
[i
], true);
250 /* print remaining entries */
251 for (i
= 0; i
< n_options
; i
++) {
254 for (j
= 0; j
< n_order
; j
++)
255 if (options
[i
] == order
[j
])
258 print_efi_option(options
[i
], false);
267 static int status_entries(const char *esp_path
, sd_id128_t partition
) {
270 _cleanup_(boot_config_free
) BootConfig config
= {};
272 printf("Default Boot Entry:\n");
274 r
= boot_entries_load_config(esp_path
, &config
);
276 return log_error_errno(r
, "Failed to load bootspec config from \"%s/loader\": %m",
279 if (config
.default_entry
< 0)
280 printf("%zu entries, no entry suitable as default\n", config
.n_entries
);
282 const BootEntry
*e
= &config
.entries
[config
.default_entry
];
284 printf(" title: %s\n", boot_entry_title(e
));
286 printf(" version: %s\n", e
->version
);
288 printf(" linux: %s\n", e
->kernel
);
289 if (!strv_isempty(e
->initrd
)) {
290 _cleanup_free_
char *t
;
292 t
= strv_join(e
->initrd
, " ");
296 printf(" initrd: %s\n", t
);
298 if (!strv_isempty(e
->options
)) {
299 _cleanup_free_
char *t
;
301 t
= strv_join(e
->options
, " ");
305 printf(" options: %s\n", t
);
308 printf(" devicetree: %s\n", e
->device_tree
);
315 static int compare_product(const char *a
, const char *b
) {
324 return x
< y
? -1 : x
> y
? 1 : 0;
326 return strncmp(a
, b
, x
);
329 static int compare_version(const char *a
, const char *b
) {
333 a
+= strcspn(a
, " ");
335 b
+= strcspn(b
, " ");
338 return strverscmp(a
, b
);
341 static int version_check(int fd_from
, const char *from
, int fd_to
, const char *to
) {
342 _cleanup_free_
char *a
= NULL
, *b
= NULL
;
345 assert(fd_from
>= 0);
350 r
= get_file_version(fd_from
, &a
);
354 log_error("Source file \"%s\" does not carry version information!", from
);
358 r
= get_file_version(fd_to
, &b
);
361 if (r
== 0 || compare_product(a
, b
) != 0) {
362 log_notice("Skipping \"%s\", since it's owned by another boot loader.", to
);
366 if (compare_version(a
, b
) < 0) {
367 log_warning("Skipping \"%s\", since a newer boot loader version exists already.", to
);
374 static int copy_file_with_version_check(const char *from
, const char *to
, bool force
) {
375 _cleanup_close_
int fd_from
= -1, fd_to
= -1;
376 _cleanup_free_
char *t
= NULL
;
379 fd_from
= open(from
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
);
381 return log_error_errno(errno
, "Failed to open \"%s\" for reading: %m", from
);
384 fd_to
= open(to
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
);
386 if (errno
!= -ENOENT
)
387 return log_error_errno(errno
, "Failed to open \"%s\" for reading: %m", to
);
389 r
= version_check(fd_from
, from
, fd_to
, to
);
393 if (lseek(fd_from
, 0, SEEK_SET
) == (off_t
) -1)
394 return log_error_errno(errno
, "Failed to seek in \"%s\": %m", from
);
396 fd_to
= safe_close(fd_to
);
400 r
= tempfn_random(to
, NULL
, &t
);
404 RUN_WITH_UMASK(0000) {
405 fd_to
= open(t
, O_WRONLY
|O_CREAT
|O_CLOEXEC
|O_EXCL
|O_NOFOLLOW
, 0644);
407 return log_error_errno(errno
, "Failed to open \"%s\" for writing: %m", t
);
410 r
= copy_bytes(fd_from
, fd_to
, (uint64_t) -1, COPY_REFLINK
);
413 return log_error_errno(r
, "Failed to copy data from \"%s\" to \"%s\": %m", from
, t
);
416 (void) copy_times(fd_from
, fd_to
);
418 if (fsync(fd_to
) < 0) {
419 (void) unlink_noerrno(t
);
420 return log_error_errno(errno
, "Failed to copy data from \"%s\" to \"%s\": %m", from
, t
);
423 (void) fsync_directory_of_file(fd_to
);
425 if (renameat(AT_FDCWD
, t
, AT_FDCWD
, to
) < 0) {
426 (void) unlink_noerrno(t
);
427 return log_error_errno(errno
, "Failed to rename \"%s\" to \"%s\": %m", t
, to
);
430 log_info("Copied \"%s\" to \"%s\".", from
, to
);
435 static int mkdir_one(const char *prefix
, const char *suffix
) {
438 p
= strjoina(prefix
, "/", suffix
);
439 if (mkdir(p
, 0700) < 0) {
441 return log_error_errno(errno
, "Failed to create \"%s\": %m", p
);
443 log_info("Created \"%s\".", p
);
448 static const char *efi_subdirs
[] = {
457 static int create_dirs(const char *esp_path
) {
461 STRV_FOREACH(i
, efi_subdirs
) {
462 r
= mkdir_one(esp_path
, *i
);
470 static int copy_one_file(const char *esp_path
, const char *name
, bool force
) {
474 p
= strjoina(BOOTLIBDIR
"/", name
);
475 q
= strjoina(esp_path
, "/EFI/systemd/", name
);
476 r
= copy_file_with_version_check(p
, q
, force
);
478 if (startswith(name
, "systemd-boot")) {
482 /* Create the EFI default boot loader name (specified for removable devices) */
483 v
= strjoina(esp_path
, "/EFI/BOOT/BOOT",
484 name
+ STRLEN("systemd-boot"));
485 ascii_strupper(strrchr(v
, '/') + 1);
487 k
= copy_file_with_version_check(p
, v
, force
);
495 static int install_binaries(const char *esp_path
, bool force
) {
497 _cleanup_closedir_
DIR *d
= NULL
;
501 /* Don't create any of these directories when we are
502 * just updating. When we update we'll drop-in our
503 * files (unless there are newer ones already), but we
504 * won't create the directories for them in the first
506 r
= create_dirs(esp_path
);
511 d
= opendir(BOOTLIBDIR
);
513 return log_error_errno(errno
, "Failed to open \""BOOTLIBDIR
"\": %m
");
515 FOREACH_DIRENT(de, d, break) {
518 if (!endswith_no_case(de->d_name, ".efi
"))
521 k = copy_one_file(esp_path, de->d_name, force);
529 static bool same_entry(uint16_t id, const sd_id128_t uuid, const char *path) {
530 _cleanup_free_ char *opath = NULL;
534 r = efi_get_boot_option(id, NULL, &ouuid, &opath, NULL);
537 if (!sd_id128_equal(uuid, ouuid))
539 if (!streq_ptr(path, opath))
545 static int find_slot(sd_id128_t uuid, const char *path, uint16_t *id) {
546 _cleanup_free_ uint16_t *options = NULL;
549 n = efi_get_boot_options(&options);
553 /* find already existing systemd-boot entry */
554 for (i = 0; i < n; i++)
555 if (same_entry(options[i], uuid, path)) {
560 /* find free slot in the sorted BootXXXX variable list */
561 for (i = 0; i < n; i++)
562 if (i != options[i]) {
567 /* use the next one */
574 static int insert_into_order(uint16_t slot, bool first) {
575 _cleanup_free_ uint16_t *order = NULL;
579 n = efi_get_boot_order(&order);
581 /* no entry, add us */
582 return efi_set_boot_order(&slot, 1);
584 /* are we the first and only one? */
585 if (n == 1 && order[0] == slot)
588 /* are we already in the boot order? */
589 for (i = 0; i < n; i++) {
590 if (order[i] != slot)
593 /* we do not require to be the first one, all is fine */
597 /* move us to the first slot */
598 memmove(order + 1, order, i * sizeof(uint16_t));
600 return efi_set_boot_order(order, n);
604 t = realloc(order, (n + 1) * sizeof(uint16_t));
609 /* add us to the top or end of the list */
611 memmove(order + 1, order, n * sizeof(uint16_t));
616 return efi_set_boot_order(order, n + 1);
619 static int remove_from_order(uint16_t slot) {
620 _cleanup_free_ uint16_t *order = NULL;
623 n = efi_get_boot_order(&order);
627 for (i = 0; i < n; i++) {
628 if (order[i] != slot)
632 memmove(order + i, order + i+1, (n - i) * sizeof(uint16_t));
633 return efi_set_boot_order(order, n - 1);
639 static int install_variables(const char *esp_path,
640 uint32_t part, uint64_t pstart, uint64_t psize,
641 sd_id128_t uuid, const char *path,
647 if (!is_efi_boot()) {
648 log_warning("Not booted with EFI
, skipping EFI variable setup
.");
652 p = strjoina(esp_path, path);
653 if (access(p, F_OK) < 0) {
657 return log_error_errno(errno, "Cannot access
\"%s
\": %m
", p);
660 r = find_slot(uuid, path, &slot);
662 return log_error_errno(r,
664 "Failed to access EFI variables
. Is the
\"efivarfs
\" filesystem mounted
?" :
665 "Failed to determine current boot order
: %m
");
667 if (first || r == 0) {
668 r = efi_add_boot_option(slot, "Linux Boot Manager
",
672 return log_error_errno(r, "Failed to create EFI Boot variable entry
: %m
");
674 log_info("Created EFI boot entry
\"Linux Boot Manager
\".");
677 return insert_into_order(slot, first);
680 static int remove_boot_efi(const char *esp_path) {
682 _cleanup_closedir_ DIR *d = NULL;
686 p = strjoina(esp_path, "/EFI
/BOOT
");
692 return log_error_errno(errno, "Failed to open directory
\"%s
\": %m
", p);
695 FOREACH_DIRENT(de, d, break) {
696 _cleanup_close_ int fd = -1;
697 _cleanup_free_ char *v = NULL;
699 if (!endswith_no_case(de->d_name, ".efi
"))
702 if (!startswith_no_case(de->d_name, "boot
"))
705 fd = openat(dirfd(d), de->d_name, O_RDONLY|O_CLOEXEC);
707 return log_error_errno(errno, "Failed to open
\"%s
/%s
\" for reading
: %m
", p, de->d_name);
709 r = get_file_version(fd, &v);
712 if (r > 0 && startswith(v, "systemd
-boot
")) {
713 r = unlinkat(dirfd(d), de->d_name, 0);
715 return log_error_errno(errno, "Failed to remove
\"%s
/%s
\": %m
", p, de->d_name);
717 log_info("Removed
\"%s
/%s
\".", p, de->d_name);
726 static int rmdir_one(const char *prefix, const char *suffix) {
729 p = strjoina(prefix, "/", suffix);
731 if (!IN_SET(errno, ENOENT, ENOTEMPTY))
732 return log_error_errno(errno, "Failed to remove
\"%s
\": %m
", p);
734 log_info("Removed
\"%s
\".", p);
739 static int remove_binaries(const char *esp_path) {
744 p = strjoina(esp_path, "/EFI
/systemd
");
745 r = rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
747 q = remove_boot_efi(esp_path);
751 for (i = ELEMENTSOF(efi_subdirs)-1; i > 0; i--) {
752 q = rmdir_one(esp_path, efi_subdirs[i-1]);
760 static int remove_variables(sd_id128_t uuid, const char *path, bool in_order) {
767 r = find_slot(uuid, path, &slot);
771 r = efi_remove_boot_option(slot);
776 return remove_from_order(slot);
781 static int install_loader_config(const char *esp_path) {
783 char machine_string[SD_ID128_STRING_MAX];
784 _cleanup_(unlink_and_freep) char *t = NULL;
785 _cleanup_fclose_ FILE *f = NULL;
786 sd_id128_t machine_id;
790 r = sd_id128_get_machine(&machine_id);
792 return log_error_errno(r, "Failed to get machine id
: %m
");
794 p = strjoina(esp_path, "/loader
/loader
.conf
");
796 if (access(p, F_OK) >= 0) /* Silently skip creation if the file already exists (early check) */
799 fd = open_tmpfile_linkable(p, O_WRONLY|O_CLOEXEC, &t);
801 return log_error_errno(fd, "Failed to open
\"%s
\" for writing
: %m
", p);
803 f = fdopen(fd, "we
");
809 fprintf(f, "#timeout 3\n");
810 fprintf(f, "#console-mode keep\n");
811 fprintf(f, "default %s-*\n", sd_id128_to_string(machine_id, machine_string));
813 r = fflush_sync_and_check(f);
815 return log_error_errno(r, "Failed to write \"%s\": %m", p);
817 r = link_tmpfile(fd, t, p);
819 return 0; /* Silently skip creation if the file exists now (recheck) */
821 return log_error_errno(r, "Failed to move \"%s\" into place: %m", p);
828 static int help(int argc, char *argv[], void *userdata) {
830 printf("%s [COMMAND] [OPTIONS...]\n"
832 "Install, update or remove the systemd-boot EFI boot manager.\n\n"
833 " -h --help Show this help\n"
834 " --version Print version\n"
835 " --path=PATH Path to the EFI System Partition (ESP)\n"
836 " -p --print-path Print path to the EFI partition\n"
837 " --no-variables Don't touch EFI variables\n"
840 " status Show status of installed systemd-boot and EFI variables\n"
841 " list List boot entries\n"
842 " install Install systemd-boot to the ESP and EFI variables\n"
843 " update Update systemd-boot in the ESP and EFI variables\n"
844 " remove Remove systemd-boot from the ESP and EFI variables\n",
845 program_invocation_short_name);
850 static int parse_argv(int argc, char *argv[]) {
857 static const struct option options[] = {
858 { "help", no_argument, NULL, 'h' },
859 { "version", no_argument, NULL, ARG_VERSION },
860 { "path", required_argument, NULL, ARG_PATH },
861 { "print-path", no_argument, NULL, 'p' },
862 { "no-variables", no_argument, NULL, ARG_NO_VARIABLES },
871 while ((c = getopt_long(argc, argv, "hp", options, NULL)) >= 0)
882 r = free_and_strdup(&arg_path, optarg);
888 arg_print_path = true;
891 case ARG_NO_VARIABLES:
892 arg_touch_variables = false;
899 assert_not_reached("Unknown option");
905 static void read_loader_efi_var(const char *name, char **var) {
908 r = efi_get_variable_string(EFI_VENDOR_LOADER, name, var);
909 if (r < 0 && r != -ENOENT)
910 log_warning_errno(r, "Failed to read EFI variable %s: %m", name);
913 static int verb_status(int argc, char *argv[], void *userdata) {
915 sd_id128_t uuid = SD_ID128_NULL;
918 r = acquire_esp(geteuid() != 0, NULL, NULL, NULL, &uuid);
920 if (arg_print_path) {
921 if (r == -EACCES) /* If we couldn't acquire the ESP path, log about access errors (which is the only
922 * error the
find_esp_and_warn() won
't log on its own) */
923 return log_error_errno(r, "Failed to determine ESP: %m");
931 r = 0; /* If we couldn't determine the path
, then don
't consider that a problem from here on, just show what we
935 _cleanup_free_ char *fw_type = NULL, *fw_info = NULL, *loader = NULL, *loader_path = NULL, *stub = NULL;
936 sd_id128_t loader_part_uuid = SD_ID128_NULL;
938 read_loader_efi_var("LoaderFirmwareType", &fw_type);
939 read_loader_efi_var("LoaderFirmwareInfo", &fw_info);
940 read_loader_efi_var("LoaderInfo", &loader);
941 read_loader_efi_var("StubInfo", &stub);
942 read_loader_efi_var("LoaderImageIdentifier", &loader_path);
945 efi_tilt_backslashes(loader_path);
947 k = efi_loader_get_device_part_uuid(&loader_part_uuid);
948 if (k < 0 && k != -ENOENT)
949 r = log_warning_errno(k, "Failed to read EFI variable LoaderDevicePartUUID: %m");
952 printf(" Firmware: %s (%s)\n", strna(fw_type), strna(fw_info));
954 k = is_efi_secure_boot();
956 r = log_warning_errno(k, "Failed to query secure boot status: %m");
958 printf(" Secure Boot: %sd\n", enable_disable(k));
960 k = is_efi_secure_boot_setup_mode();
962 r = log_warning_errno(k, "Failed to query secure boot mode: %m");
964 printf(" Setup Mode: %s\n", k ? "setup" : "user");
967 printf("Current Loader:\n");
968 printf(" Product: %s\n", strna(loader));
970 printf(" Stub: %s\n", stub);
971 if (!sd_id128_is_null(loader_part_uuid))
972 printf(" ESP: /dev/disk/by-partuuid/%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
973 SD_ID128_FORMAT_VAL(loader_part_uuid));
975 printf(" ESP: n/a\n");
976 printf(" File: %s%s\n", special_glyph(TREE_RIGHT), strna(loader_path));
979 printf("System:\n Not booted with EFI\n\n");
982 k = status_binaries(arg_path, uuid);
988 k = status_variables();
994 k = status_entries(arg_path, uuid);
1002 static int verb_list(int argc, char *argv[], void *userdata) {
1003 _cleanup_(boot_config_free) BootConfig config = {};
1004 sd_id128_t uuid = SD_ID128_NULL;
1008 /* If we lack privileges we invoke find_esp_and_warn() in "unprivileged mode" here, which does two things: turn
1009 * off logging about access errors and turn off potentially privileged device probing. Here we're interested in
1010 * the latter but
not the former
, hence request the mode
, and log about EACCES
. */
1012 r
= acquire_esp(geteuid() != 0, NULL
, NULL
, NULL
, &uuid
);
1013 if (r
== -EACCES
) /* We really need the ESP path for this call, hence also log about access errors */
1014 return log_error_errno(r
, "Failed to determine ESP: %m");
1018 r
= boot_entries_load_config(arg_path
, &config
);
1020 return log_error_errno(r
, "Failed to load bootspec config from \"%s/loader\": %m",
1023 printf("Available boot entries:\n");
1025 for (n
= 0; n
< config
.n_entries
; n
++) {
1026 const BootEntry
*e
= &config
.entries
[n
];
1028 printf(" title: %s%s%s%s%s%s\n",
1030 boot_entry_title(e
),
1032 ansi_highlight_green(),
1033 n
== (unsigned) config
.default_entry
? " (default)" : "",
1036 printf(" version: %s\n", e
->version
);
1038 printf(" machine-id: %s\n", e
->machine_id
);
1039 if (e
->architecture
)
1040 printf(" architecture: %s\n", e
->architecture
);
1042 printf(" linux: %s\n", e
->kernel
);
1043 if (!strv_isempty(e
->initrd
)) {
1044 _cleanup_free_
char *t
;
1046 t
= strv_join(e
->initrd
, " ");
1050 printf(" initrd: %s\n", t
);
1052 if (!strv_isempty(e
->options
)) {
1053 _cleanup_free_
char *t
;
1055 t
= strv_join(e
->options
, " ");
1059 printf(" options: %s\n", t
);
1062 printf(" devicetree: %s\n", e
->device_tree
);
1070 static int verb_install(int argc
, char *argv
[], void *userdata
) {
1072 sd_id128_t uuid
= SD_ID128_NULL
;
1073 uint64_t pstart
= 0, psize
= 0;
1078 r
= acquire_esp(false, &part
, &pstart
, &psize
, &uuid
);
1082 install
= streq(argv
[0], "install");
1084 RUN_WITH_UMASK(0002) {
1085 r
= install_binaries(arg_path
, install
);
1090 r
= install_loader_config(arg_path
);
1096 if (arg_touch_variables
)
1097 r
= install_variables(arg_path
,
1098 part
, pstart
, psize
, uuid
,
1099 "/EFI/systemd/systemd-boot" EFI_MACHINE_TYPE_NAME
".efi",
1105 static int verb_remove(int argc
, char *argv
[], void *userdata
) {
1106 sd_id128_t uuid
= SD_ID128_NULL
;
1109 r
= acquire_esp(false, NULL
, NULL
, NULL
, &uuid
);
1113 r
= remove_binaries(arg_path
);
1115 if (arg_touch_variables
) {
1118 q
= remove_variables(uuid
, "/EFI/systemd/systemd-boot" EFI_MACHINE_TYPE_NAME
".efi", true);
1119 if (q
< 0 && r
== 0)
1126 static int bootctl_main(int argc
, char *argv
[]) {
1128 static const Verb verbs
[] = {
1129 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
1130 { "status", VERB_ANY
, 1, VERB_DEFAULT
, verb_status
},
1131 { "list", VERB_ANY
, 1, 0, verb_list
},
1132 { "install", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_install
},
1133 { "update", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_install
},
1134 { "remove", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_remove
},
1138 return dispatch_verb(argc
, argv
, verbs
, NULL
);
1141 int main(int argc
, char *argv
[]) {
1144 log_parse_environment();
1147 /* If we run in a container, automatically turn of EFI file system access */
1148 if (detect_container() > 0)
1149 arg_touch_variables
= false;
1151 r
= parse_argv(argc
, argv
);
1155 r
= bootctl_main(argc
, argv
);
1159 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;