1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2013-2015 Kay Sievers
13 #include <linux/magic.h>
20 #include <sys/statfs.h>
25 #include "alloc-util.h"
26 #include "blkid-util.h"
29 #include "dirent-util.h"
34 #include "locale-util.h"
35 #include "parse-util.h"
37 #include "stat-util.h"
38 #include "string-util.h"
40 #include "terminal-util.h"
41 #include "umask-util.h"
46 static char *arg_path
= NULL
;
47 static bool arg_print_path
= false;
48 static bool arg_touch_variables
= true;
50 static int acquire_esp(
51 bool unprivileged_mode
,
55 sd_id128_t
*ret_uuid
) {
60 /* Find the ESP, and log about errors. Note that find_esp_and_warn() will log in all error cases on its own,
61 * except for ENOKEY (which is good, we want to show our own message in that case, suggesting use of --path=)
62 * and EACCESS (only when we request unprivileged mode; in this case we simply eat up the error here, so that
63 * --list and --status work too, without noise about this). */
65 r
= find_esp_and_warn(arg_path
, unprivileged_mode
, &np
, ret_part
, ret_pstart
, ret_psize
, ret_uuid
);
67 return log_error_errno(r
,
68 "Couldn't find EFI system partition. It is recommended to mount it to /boot or /efi.\n"
69 "Alternatively, use --path= to specify path to mount point.");
73 free_and_replace(arg_path
, np
);
75 log_debug("Using EFI System Partition at %s.", arg_path
);
80 /* search for "#### LoaderInfo: systemd-boot 218 ####" string inside the binary */
81 static int get_file_version(int fd
, char **v
) {
91 if (fstat(fd
, &st
) < 0)
92 return log_error_errno(errno
, "Failed to stat EFI binary: %m");
94 if (st
.st_size
< 27) {
99 buf
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
100 if (buf
== MAP_FAILED
)
101 return log_error_errno(errno
, "Failed to memory map EFI binary: %m");
103 s
= memmem(buf
, st
.st_size
- 8, "#### LoaderInfo: ", 17);
108 e
= memmem(s
, st
.st_size
- (s
- buf
), " ####", 5);
109 if (!e
|| e
- s
< 3) {
110 log_error("Malformed version string.");
115 x
= strndup(s
, e
- s
);
123 (void) munmap(buf
, st
.st_size
);
128 static int enumerate_binaries(const char *esp_path
, const char *path
, const char *prefix
) {
130 _cleanup_closedir_
DIR *d
= NULL
;
134 p
= strjoina(esp_path
, "/", path
);
140 return log_error_errno(errno
, "Failed to read \"%s\": %m", p
);
143 FOREACH_DIRENT(de
, d
, break) {
144 _cleanup_close_
int fd
= -1;
145 _cleanup_free_
char *v
= NULL
;
147 if (!endswith_no_case(de
->d_name
, ".efi"))
150 if (prefix
&& !startswith_no_case(de
->d_name
, prefix
))
153 fd
= openat(dirfd(d
), de
->d_name
, O_RDONLY
|O_CLOEXEC
);
155 return log_error_errno(errno
, "Failed to open \"%s/%s\" for reading: %m", p
, de
->d_name
);
157 r
= get_file_version(fd
, &v
);
161 printf(" File: %s/%s/%s (%s)\n", special_glyph(TREE_RIGHT
), path
, de
->d_name
, v
);
163 printf(" File: %s/%s/%s\n", special_glyph(TREE_RIGHT
), path
, de
->d_name
);
170 static int status_binaries(const char *esp_path
, sd_id128_t partition
) {
173 printf("Boot Loader Binaries:\n");
176 printf(" ESP: Cannot find or access mount point of ESP.\n\n");
180 printf(" ESP: %s", esp_path
);
181 if (!sd_id128_is_null(partition
))
182 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
));
185 r
= enumerate_binaries(esp_path
, "EFI/systemd", NULL
);
187 log_error("systemd-boot not installed in ESP.");
191 r
= enumerate_binaries(esp_path
, "EFI/BOOT", "boot");
193 log_error("No default/fallback boot loader installed in ESP.");
202 static int print_efi_option(uint16_t id
, bool in_order
) {
203 _cleanup_free_
char *title
= NULL
;
204 _cleanup_free_
char *path
= NULL
;
205 sd_id128_t partition
;
209 r
= efi_get_boot_option(id
, &title
, &partition
, &path
, &active
);
213 /* print only configured entries with partition information */
214 if (!path
|| sd_id128_is_null(partition
))
217 efi_tilt_backslashes(path
);
219 printf(" Title: %s\n", strna(title
));
220 printf(" ID: 0x%04X\n", id
);
221 printf(" Status: %sactive%s\n", active
? "" : "in", in_order
? ", boot-order" : "");
222 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
));
223 printf(" File: %s%s\n", special_glyph(TREE_RIGHT
), path
);
229 static int status_variables(void) {
230 int n_options
, n_order
;
231 _cleanup_free_
uint16_t *options
= NULL
, *order
= NULL
;
234 n_options
= efi_get_boot_options(&options
);
235 if (n_options
== -ENOENT
)
236 return log_error_errno(n_options
,
237 "Failed to access EFI variables, efivarfs"
238 " needs to be available at /sys/firmware/efi/efivars/.");
240 return log_error_errno(n_options
, "Failed to read EFI boot entries: %m");
242 n_order
= efi_get_boot_order(&order
);
243 if (n_order
== -ENOENT
)
245 else if (n_order
< 0)
246 return log_error_errno(n_order
, "Failed to read EFI boot order.");
248 /* print entries in BootOrder first */
249 printf("Boot Loader Entries in EFI Variables:\n");
250 for (i
= 0; i
< n_order
; i
++)
251 print_efi_option(order
[i
], true);
253 /* print remaining entries */
254 for (i
= 0; i
< n_options
; i
++) {
257 for (j
= 0; j
< n_order
; j
++)
258 if (options
[i
] == order
[j
])
261 print_efi_option(options
[i
], false);
270 static int status_entries(const char *esp_path
, sd_id128_t partition
) {
273 _cleanup_(boot_config_free
) BootConfig config
= {};
275 printf("Default Boot Entry:\n");
277 r
= boot_entries_load_config(esp_path
, &config
);
279 return log_error_errno(r
, "Failed to load bootspec config from \"%s/loader\": %m",
282 if (config
.default_entry
< 0)
283 printf("%zu entries, no entry suitable as default\n", config
.n_entries
);
285 const BootEntry
*e
= &config
.entries
[config
.default_entry
];
287 printf(" title: %s\n", boot_entry_title(e
));
289 printf(" version: %s\n", e
->version
);
291 printf(" linux: %s\n", e
->kernel
);
292 if (!strv_isempty(e
->initrd
)) {
293 _cleanup_free_
char *t
;
295 t
= strv_join(e
->initrd
, " ");
299 printf(" initrd: %s\n", t
);
301 if (!strv_isempty(e
->options
)) {
302 _cleanup_free_
char *t
;
304 t
= strv_join(e
->options
, " ");
308 printf(" options: %s\n", t
);
311 printf(" devicetree: %s\n", e
->device_tree
);
318 static int compare_product(const char *a
, const char *b
) {
327 return x
< y
? -1 : x
> y
? 1 : 0;
329 return strncmp(a
, b
, x
);
332 static int compare_version(const char *a
, const char *b
) {
336 a
+= strcspn(a
, " ");
338 b
+= strcspn(b
, " ");
341 return strverscmp(a
, b
);
344 static int version_check(int fd_from
, const char *from
, int fd_to
, const char *to
) {
345 _cleanup_free_
char *a
= NULL
, *b
= NULL
;
348 assert(fd_from
>= 0);
353 r
= get_file_version(fd_from
, &a
);
357 log_error("Source file \"%s\" does not carry version information!", from
);
361 r
= get_file_version(fd_to
, &b
);
364 if (r
== 0 || compare_product(a
, b
) != 0) {
365 log_notice("Skipping \"%s\", since it's owned by another boot loader.", to
);
369 if (compare_version(a
, b
) < 0) {
370 log_warning("Skipping \"%s\", since a newer boot loader version exists already.", to
);
377 static int copy_file_with_version_check(const char *from
, const char *to
, bool force
) {
378 _cleanup_close_
int fd_from
= -1, fd_to
= -1;
379 _cleanup_free_
char *t
= NULL
;
382 fd_from
= open(from
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
);
384 return log_error_errno(errno
, "Failed to open \"%s\" for reading: %m", from
);
387 fd_to
= open(to
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
);
389 if (errno
!= -ENOENT
)
390 return log_error_errno(errno
, "Failed to open \"%s\" for reading: %m", to
);
392 r
= version_check(fd_from
, from
, fd_to
, to
);
396 if (lseek(fd_from
, 0, SEEK_SET
) == (off_t
) -1)
397 return log_error_errno(errno
, "Failed to seek in \"%s\": %m", from
);
399 fd_to
= safe_close(fd_to
);
403 r
= tempfn_random(to
, NULL
, &t
);
407 RUN_WITH_UMASK(0000) {
408 fd_to
= open(t
, O_WRONLY
|O_CREAT
|O_CLOEXEC
|O_EXCL
|O_NOFOLLOW
, 0644);
410 return log_error_errno(errno
, "Failed to open \"%s\" for writing: %m", t
);
413 r
= copy_bytes(fd_from
, fd_to
, (uint64_t) -1, COPY_REFLINK
);
416 return log_error_errno(r
, "Failed to copy data from \"%s\" to \"%s\": %m", from
, t
);
419 (void) copy_times(fd_from
, fd_to
);
421 if (fsync(fd_to
) < 0) {
422 (void) unlink_noerrno(t
);
423 return log_error_errno(errno
, "Failed to copy data from \"%s\" to \"%s\": %m", from
, t
);
426 (void) fsync_directory_of_file(fd_to
);
428 if (renameat(AT_FDCWD
, t
, AT_FDCWD
, to
) < 0) {
429 (void) unlink_noerrno(t
);
430 return log_error_errno(errno
, "Failed to rename \"%s\" to \"%s\": %m", t
, to
);
433 log_info("Copied \"%s\" to \"%s\".", from
, to
);
438 static int mkdir_one(const char *prefix
, const char *suffix
) {
441 p
= strjoina(prefix
, "/", suffix
);
442 if (mkdir(p
, 0700) < 0) {
444 return log_error_errno(errno
, "Failed to create \"%s\": %m", p
);
446 log_info("Created \"%s\".", p
);
451 static const char *efi_subdirs
[] = {
460 static int create_dirs(const char *esp_path
) {
464 STRV_FOREACH(i
, efi_subdirs
) {
465 r
= mkdir_one(esp_path
, *i
);
473 static int copy_one_file(const char *esp_path
, const char *name
, bool force
) {
477 p
= strjoina(BOOTLIBDIR
"/", name
);
478 q
= strjoina(esp_path
, "/EFI/systemd/", name
);
479 r
= copy_file_with_version_check(p
, q
, force
);
481 if (startswith(name
, "systemd-boot")) {
485 /* Create the EFI default boot loader name (specified for removable devices) */
486 v
= strjoina(esp_path
, "/EFI/BOOT/BOOT",
487 name
+ STRLEN("systemd-boot"));
488 ascii_strupper(strrchr(v
, '/') + 1);
490 k
= copy_file_with_version_check(p
, v
, force
);
498 static int install_binaries(const char *esp_path
, bool force
) {
500 _cleanup_closedir_
DIR *d
= NULL
;
504 /* Don't create any of these directories when we are
505 * just updating. When we update we'll drop-in our
506 * files (unless there are newer ones already), but we
507 * won't create the directories for them in the first
509 r
= create_dirs(esp_path
);
514 d
= opendir(BOOTLIBDIR
);
516 return log_error_errno(errno
, "Failed to open \""BOOTLIBDIR
"\": %m
");
518 FOREACH_DIRENT(de, d, break) {
521 if (!endswith_no_case(de->d_name, ".efi
"))
524 k = copy_one_file(esp_path, de->d_name, force);
532 static bool same_entry(uint16_t id, const sd_id128_t uuid, const char *path) {
533 _cleanup_free_ char *opath = NULL;
537 r = efi_get_boot_option(id, NULL, &ouuid, &opath, NULL);
540 if (!sd_id128_equal(uuid, ouuid))
542 if (!streq_ptr(path, opath))
548 static int find_slot(sd_id128_t uuid, const char *path, uint16_t *id) {
549 _cleanup_free_ uint16_t *options = NULL;
552 n = efi_get_boot_options(&options);
556 /* find already existing systemd-boot entry */
557 for (i = 0; i < n; i++)
558 if (same_entry(options[i], uuid, path)) {
563 /* find free slot in the sorted BootXXXX variable list */
564 for (i = 0; i < n; i++)
565 if (i != options[i]) {
570 /* use the next one */
577 static int insert_into_order(uint16_t slot, bool first) {
578 _cleanup_free_ uint16_t *order = NULL;
582 n = efi_get_boot_order(&order);
584 /* no entry, add us */
585 return efi_set_boot_order(&slot, 1);
587 /* are we the first and only one? */
588 if (n == 1 && order[0] == slot)
591 /* are we already in the boot order? */
592 for (i = 0; i < n; i++) {
593 if (order[i] != slot)
596 /* we do not require to be the first one, all is fine */
600 /* move us to the first slot */
601 memmove(order + 1, order, i * sizeof(uint16_t));
603 return efi_set_boot_order(order, n);
607 t = realloc(order, (n + 1) * sizeof(uint16_t));
612 /* add us to the top or end of the list */
614 memmove(order + 1, order, n * sizeof(uint16_t));
619 return efi_set_boot_order(order, n + 1);
622 static int remove_from_order(uint16_t slot) {
623 _cleanup_free_ uint16_t *order = NULL;
626 n = efi_get_boot_order(&order);
630 for (i = 0; i < n; i++) {
631 if (order[i] != slot)
635 memmove(order + i, order + i+1, (n - i) * sizeof(uint16_t));
636 return efi_set_boot_order(order, n - 1);
642 static int install_variables(const char *esp_path,
643 uint32_t part, uint64_t pstart, uint64_t psize,
644 sd_id128_t uuid, const char *path,
650 if (!is_efi_boot()) {
651 log_warning("Not booted with EFI
, skipping EFI variable setup
.");
655 p = strjoina(esp_path, path);
656 if (access(p, F_OK) < 0) {
660 return log_error_errno(errno, "Cannot access
\"%s
\": %m
", p);
663 r = find_slot(uuid, path, &slot);
665 return log_error_errno(r,
667 "Failed to access EFI variables
. Is the
\"efivarfs
\" filesystem mounted
?" :
668 "Failed to determine current boot order
: %m
");
670 if (first || r == 0) {
671 r = efi_add_boot_option(slot, "Linux Boot Manager
",
675 return log_error_errno(r, "Failed to create EFI Boot variable entry
: %m
");
677 log_info("Created EFI boot entry
\"Linux Boot Manager
\".");
680 return insert_into_order(slot, first);
683 static int remove_boot_efi(const char *esp_path) {
685 _cleanup_closedir_ DIR *d = NULL;
689 p = strjoina(esp_path, "/EFI
/BOOT
");
695 return log_error_errno(errno, "Failed to open directory
\"%s
\": %m
", p);
698 FOREACH_DIRENT(de, d, break) {
699 _cleanup_close_ int fd = -1;
700 _cleanup_free_ char *v = NULL;
702 if (!endswith_no_case(de->d_name, ".efi
"))
705 if (!startswith_no_case(de->d_name, "boot
"))
708 fd = openat(dirfd(d), de->d_name, O_RDONLY|O_CLOEXEC);
710 return log_error_errno(errno, "Failed to open
\"%s
/%s
\" for reading
: %m
", p, de->d_name);
712 r = get_file_version(fd, &v);
715 if (r > 0 && startswith(v, "systemd
-boot
")) {
716 r = unlinkat(dirfd(d), de->d_name, 0);
718 return log_error_errno(errno, "Failed to remove
\"%s
/%s
\": %m
", p, de->d_name);
720 log_info("Removed
\"%s
/%s
\".", p, de->d_name);
729 static int rmdir_one(const char *prefix, const char *suffix) {
732 p = strjoina(prefix, "/", suffix);
734 if (!IN_SET(errno, ENOENT, ENOTEMPTY))
735 return log_error_errno(errno, "Failed to remove
\"%s
\": %m
", p);
737 log_info("Removed
\"%s
\".", p);
742 static int remove_binaries(const char *esp_path) {
747 p = strjoina(esp_path, "/EFI
/systemd
");
748 r = rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
750 q = remove_boot_efi(esp_path);
754 for (i = ELEMENTSOF(efi_subdirs)-1; i > 0; i--) {
755 q = rmdir_one(esp_path, efi_subdirs[i-1]);
763 static int remove_variables(sd_id128_t uuid, const char *path, bool in_order) {
770 r = find_slot(uuid, path, &slot);
774 r = efi_remove_boot_option(slot);
779 return remove_from_order(slot);
784 static int install_loader_config(const char *esp_path) {
786 char machine_string[SD_ID128_STRING_MAX];
787 _cleanup_(unlink_and_freep) char *t = NULL;
788 _cleanup_fclose_ FILE *f = NULL;
789 sd_id128_t machine_id;
793 r = sd_id128_get_machine(&machine_id);
795 return log_error_errno(r, "Failed to get machine id
: %m
");
797 p = strjoina(esp_path, "/loader
/loader
.conf
");
799 if (access(p, F_OK) >= 0) /* Silently skip creation if the file already exists (early check) */
802 fd = open_tmpfile_linkable(p, O_WRONLY|O_CLOEXEC, &t);
804 return log_error_errno(fd, "Failed to open
\"%s
\" for writing
: %m
", p);
806 f = fdopen(fd, "we
");
812 fprintf(f, "#timeout 3\n");
813 fprintf(f, "#console-mode keep\n");
814 fprintf(f, "default %s-*\n", sd_id128_to_string(machine_id, machine_string));
816 r = fflush_sync_and_check(f);
818 return log_error_errno(r, "Failed to write \"%s\": %m", p);
820 r = link_tmpfile(fd, t, p);
822 return 0; /* Silently skip creation if the file exists now (recheck) */
824 return log_error_errno(r, "Failed to move \"%s\" into place: %m", p);
831 static int help(int argc, char *argv[], void *userdata) {
833 printf("%s [COMMAND] [OPTIONS...]\n"
835 "Install, update or remove the systemd-boot EFI boot manager.\n\n"
836 " -h --help Show this help\n"
837 " --version Print version\n"
838 " --path=PATH Path to the EFI System Partition (ESP)\n"
839 " -p --print-path Print path to the EFI partition\n"
840 " --no-variables Don't touch EFI variables\n"
843 " status Show status of installed systemd-boot and EFI variables\n"
844 " list List boot entries\n"
845 " install Install systemd-boot to the ESP and EFI variables\n"
846 " update Update systemd-boot in the ESP and EFI variables\n"
847 " remove Remove systemd-boot from the ESP and EFI variables\n",
848 program_invocation_short_name);
853 static int parse_argv(int argc, char *argv[]) {
860 static const struct option options[] = {
861 { "help", no_argument, NULL, 'h' },
862 { "version", no_argument, NULL, ARG_VERSION },
863 { "path", required_argument, NULL, ARG_PATH },
864 { "print-path", no_argument, NULL, 'p' },
865 { "no-variables", no_argument, NULL, ARG_NO_VARIABLES },
874 while ((c = getopt_long(argc, argv, "hp", options, NULL)) >= 0)
885 r = free_and_strdup(&arg_path, optarg);
891 arg_print_path = true;
894 case ARG_NO_VARIABLES:
895 arg_touch_variables = false;
902 assert_not_reached("Unknown option");
908 static void read_loader_efi_var(const char *name, char **var) {
911 r = efi_get_variable_string(EFI_VENDOR_LOADER, name, var);
912 if (r < 0 && r != -ENOENT)
913 log_warning_errno(r, "Failed to read EFI variable %s: %m", name);
916 static int verb_status(int argc, char *argv[], void *userdata) {
918 sd_id128_t uuid = SD_ID128_NULL;
921 r = acquire_esp(geteuid() != 0, NULL, NULL, NULL, &uuid);
923 if (arg_print_path) {
924 if (r == -EACCES) /* If we couldn't acquire the ESP path, log about access errors (which is the only
925 * error the
find_esp_and_warn() won
't log on its own) */
926 return log_error_errno(r, "Failed to determine ESP: %m");
934 r = 0; /* If we couldn't determine the path
, then don
't consider that a problem from here on, just show what we
938 _cleanup_free_ char *fw_type = NULL, *fw_info = NULL, *loader = NULL, *loader_path = NULL, *stub = NULL;
939 sd_id128_t loader_part_uuid = SD_ID128_NULL;
941 read_loader_efi_var("LoaderFirmwareType", &fw_type);
942 read_loader_efi_var("LoaderFirmwareInfo", &fw_info);
943 read_loader_efi_var("LoaderInfo", &loader);
944 read_loader_efi_var("StubInfo", &stub);
945 read_loader_efi_var("LoaderImageIdentifier", &loader_path);
948 efi_tilt_backslashes(loader_path);
950 k = efi_loader_get_device_part_uuid(&loader_part_uuid);
951 if (k < 0 && k != -ENOENT)
952 r = log_warning_errno(k, "Failed to read EFI variable LoaderDevicePartUUID: %m");
955 printf(" Firmware: %s (%s)\n", strna(fw_type), strna(fw_info));
957 k = is_efi_secure_boot();
959 r = log_warning_errno(k, "Failed to query secure boot status: %m");
961 printf(" Secure Boot: %sd\n", enable_disable(k));
963 k = is_efi_secure_boot_setup_mode();
965 r = log_warning_errno(k, "Failed to query secure boot mode: %m");
967 printf(" Setup Mode: %s\n", k ? "setup" : "user");
970 printf("Current Loader:\n");
971 printf(" Product: %s\n", strna(loader));
973 printf(" Stub: %s\n", stub);
974 if (!sd_id128_is_null(loader_part_uuid))
975 printf(" ESP: /dev/disk/by-partuuid/%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
976 SD_ID128_FORMAT_VAL(loader_part_uuid));
978 printf(" ESP: n/a\n");
979 printf(" File: %s%s\n", special_glyph(TREE_RIGHT), strna(loader_path));
982 printf("System:\n Not booted with EFI\n\n");
985 k = status_binaries(arg_path, uuid);
991 k = status_variables();
997 k = status_entries(arg_path, uuid);
1005 static int verb_list(int argc, char *argv[], void *userdata) {
1006 _cleanup_(boot_config_free) BootConfig config = {};
1007 sd_id128_t uuid = SD_ID128_NULL;
1011 /* If we lack privileges we invoke find_esp_and_warn() in "unprivileged mode" here, which does two things: turn
1012 * off logging about access errors and turn off potentially privileged device probing. Here we're interested in
1013 * the latter but
not the former
, hence request the mode
, and log about EACCES
. */
1015 r
= acquire_esp(geteuid() != 0, NULL
, NULL
, NULL
, &uuid
);
1016 if (r
== -EACCES
) /* We really need the ESP path for this call, hence also log about access errors */
1017 return log_error_errno(r
, "Failed to determine ESP: %m");
1021 r
= boot_entries_load_config(arg_path
, &config
);
1023 return log_error_errno(r
, "Failed to load bootspec config from \"%s/loader\": %m",
1026 printf("Available boot entries:\n");
1028 for (n
= 0; n
< config
.n_entries
; n
++) {
1029 const BootEntry
*e
= &config
.entries
[n
];
1031 printf(" title: %s%s%s%s%s%s\n",
1033 boot_entry_title(e
),
1035 ansi_highlight_green(),
1036 n
== (unsigned) config
.default_entry
? " (default)" : "",
1039 printf(" version: %s\n", e
->version
);
1041 printf(" machine-id: %s\n", e
->machine_id
);
1042 if (e
->architecture
)
1043 printf(" architecture: %s\n", e
->architecture
);
1045 printf(" linux: %s\n", e
->kernel
);
1046 if (!strv_isempty(e
->initrd
)) {
1047 _cleanup_free_
char *t
;
1049 t
= strv_join(e
->initrd
, " ");
1053 printf(" initrd: %s\n", t
);
1055 if (!strv_isempty(e
->options
)) {
1056 _cleanup_free_
char *t
;
1058 t
= strv_join(e
->options
, " ");
1062 printf(" options: %s\n", t
);
1065 printf(" devicetree: %s\n", e
->device_tree
);
1073 static int verb_install(int argc
, char *argv
[], void *userdata
) {
1075 sd_id128_t uuid
= SD_ID128_NULL
;
1076 uint64_t pstart
= 0, psize
= 0;
1081 r
= acquire_esp(false, &part
, &pstart
, &psize
, &uuid
);
1085 install
= streq(argv
[0], "install");
1087 RUN_WITH_UMASK(0002) {
1088 r
= install_binaries(arg_path
, install
);
1093 r
= install_loader_config(arg_path
);
1099 if (arg_touch_variables
)
1100 r
= install_variables(arg_path
,
1101 part
, pstart
, psize
, uuid
,
1102 "/EFI/systemd/systemd-boot" EFI_MACHINE_TYPE_NAME
".efi",
1108 static int verb_remove(int argc
, char *argv
[], void *userdata
) {
1109 sd_id128_t uuid
= SD_ID128_NULL
;
1112 r
= acquire_esp(false, NULL
, NULL
, NULL
, &uuid
);
1116 r
= remove_binaries(arg_path
);
1118 if (arg_touch_variables
) {
1121 q
= remove_variables(uuid
, "/EFI/systemd/systemd-boot" EFI_MACHINE_TYPE_NAME
".efi", true);
1122 if (q
< 0 && r
== 0)
1129 static int bootctl_main(int argc
, char *argv
[]) {
1131 static const Verb verbs
[] = {
1132 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
1133 { "status", VERB_ANY
, 1, VERB_DEFAULT
, verb_status
},
1134 { "list", VERB_ANY
, 1, 0, verb_list
},
1135 { "install", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_install
},
1136 { "update", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_install
},
1137 { "remove", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_remove
},
1141 return dispatch_verb(argc
, argv
, verbs
, NULL
);
1144 int main(int argc
, char *argv
[]) {
1147 log_parse_environment();
1150 /* If we run in a container, automatically turn of EFI file system access */
1151 if (detect_container() > 0)
1152 arg_touch_variables
= false;
1154 r
= parse_argv(argc
, argv
);
1158 r
= bootctl_main(argc
, argv
);
1162 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;