1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2013-2015 Kay Sievers
6 Copyright 2013 Lennart Poettering
16 #include <linux/magic.h>
23 #include <sys/statfs.h>
28 #include "alloc-util.h"
29 #include "blkid-util.h"
32 #include "dirent-util.h"
37 #include "locale-util.h"
38 #include "parse-util.h"
40 #include "stat-util.h"
41 #include "string-util.h"
43 #include "terminal-util.h"
44 #include "umask-util.h"
49 static char *arg_path
= NULL
;
50 static bool arg_print_path
= false;
51 static bool arg_touch_variables
= true;
53 static int acquire_esp(
54 bool unprivileged_mode
,
58 sd_id128_t
*ret_uuid
) {
63 /* Find the ESP, and log about errors. Note that find_esp_and_warn() will log in all error cases on its own,
64 * except for ENOKEY (which is good, we want to show our own message in that case, suggesting use of --path=)
65 * and EACCESS (only when we request unprivileged mode; in this case we simply eat up the error here, so that
66 * --list and --status work too, without noise about this). */
68 r
= find_esp_and_warn(arg_path
, unprivileged_mode
, &np
, ret_part
, ret_pstart
, ret_psize
, ret_uuid
);
70 return log_error_errno(r
,
71 "Couldn't find EFI system partition. It is recommended to mount it to /boot or /efi.\n"
72 "Alternatively, use --path= to specify path to mount point.");
76 free_and_replace(arg_path
, np
);
78 log_debug("Using EFI System Partition at %s.", arg_path
);
83 /* search for "#### LoaderInfo: systemd-boot 218 ####" string inside the binary */
84 static int get_file_version(int fd
, char **v
) {
94 if (fstat(fd
, &st
) < 0)
95 return log_error_errno(errno
, "Failed to stat EFI binary: %m");
97 if (st
.st_size
< 27) {
102 buf
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
103 if (buf
== MAP_FAILED
)
104 return log_error_errno(errno
, "Failed to memory map EFI binary: %m");
106 s
= memmem(buf
, st
.st_size
- 8, "#### LoaderInfo: ", 17);
111 e
= memmem(s
, st
.st_size
- (s
- buf
), " ####", 5);
112 if (!e
|| e
- s
< 3) {
113 log_error("Malformed version string.");
118 x
= strndup(s
, e
- s
);
126 (void) munmap(buf
, st
.st_size
);
131 static int enumerate_binaries(const char *esp_path
, const char *path
, const char *prefix
) {
133 _cleanup_closedir_
DIR *d
= NULL
;
137 p
= strjoina(esp_path
, "/", path
);
143 return log_error_errno(errno
, "Failed to read \"%s\": %m", p
);
146 FOREACH_DIRENT(de
, d
, break) {
147 _cleanup_close_
int fd
= -1;
148 _cleanup_free_
char *v
= NULL
;
150 if (!endswith_no_case(de
->d_name
, ".efi"))
153 if (prefix
&& !startswith_no_case(de
->d_name
, prefix
))
156 fd
= openat(dirfd(d
), de
->d_name
, O_RDONLY
|O_CLOEXEC
);
158 return log_error_errno(errno
, "Failed to open \"%s/%s\" for reading: %m", p
, de
->d_name
);
160 r
= get_file_version(fd
, &v
);
164 printf(" File: %s/%s/%s (%s)\n", special_glyph(TREE_RIGHT
), path
, de
->d_name
, v
);
166 printf(" File: %s/%s/%s\n", special_glyph(TREE_RIGHT
), path
, de
->d_name
);
173 static int status_binaries(const char *esp_path
, sd_id128_t partition
) {
176 printf("Boot Loader Binaries:\n");
179 printf(" ESP: Cannot find or access mount point of ESP.\n\n");
183 printf(" ESP: %s", esp_path
);
184 if (!sd_id128_is_null(partition
))
185 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
));
188 r
= enumerate_binaries(esp_path
, "EFI/systemd", NULL
);
190 log_error("systemd-boot not installed in ESP.");
194 r
= enumerate_binaries(esp_path
, "EFI/BOOT", "boot");
196 log_error("No default/fallback boot loader installed in ESP.");
205 static int print_efi_option(uint16_t id
, bool in_order
) {
206 _cleanup_free_
char *title
= NULL
;
207 _cleanup_free_
char *path
= NULL
;
208 sd_id128_t partition
;
212 r
= efi_get_boot_option(id
, &title
, &partition
, &path
, &active
);
216 /* print only configured entries with partition information */
217 if (!path
|| sd_id128_is_null(partition
))
220 efi_tilt_backslashes(path
);
222 printf(" Title: %s\n", strna(title
));
223 printf(" ID: 0x%04X\n", id
);
224 printf(" Status: %sactive%s\n", active
? "" : "in", in_order
? ", boot-order" : "");
225 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
));
226 printf(" File: %s%s\n", special_glyph(TREE_RIGHT
), path
);
232 static int status_variables(void) {
233 int n_options
, n_order
;
234 _cleanup_free_
uint16_t *options
= NULL
, *order
= NULL
;
237 n_options
= efi_get_boot_options(&options
);
238 if (n_options
== -ENOENT
)
239 return log_error_errno(n_options
,
240 "Failed to access EFI variables, efivarfs"
241 " needs to be available at /sys/firmware/efi/efivars/.");
243 return log_error_errno(n_options
, "Failed to read EFI boot entries: %m");
245 n_order
= efi_get_boot_order(&order
);
246 if (n_order
== -ENOENT
)
248 else if (n_order
< 0)
249 return log_error_errno(n_order
, "Failed to read EFI boot order.");
251 /* print entries in BootOrder first */
252 printf("Boot Loader Entries in EFI Variables:\n");
253 for (i
= 0; i
< n_order
; i
++)
254 print_efi_option(order
[i
], true);
256 /* print remaining entries */
257 for (i
= 0; i
< n_options
; i
++) {
260 for (j
= 0; j
< n_order
; j
++)
261 if (options
[i
] == order
[j
])
264 print_efi_option(options
[i
], false);
273 static int status_entries(const char *esp_path
, sd_id128_t partition
) {
276 _cleanup_(boot_config_free
) BootConfig config
= {};
278 printf("Default Boot Entry:\n");
280 r
= boot_entries_load_config(esp_path
, &config
);
282 return log_error_errno(r
, "Failed to load bootspec config from \"%s/loader\": %m",
285 if (config
.default_entry
< 0)
286 printf("%zu entries, no entry suitable as default\n", config
.n_entries
);
288 const BootEntry
*e
= &config
.entries
[config
.default_entry
];
290 printf(" title: %s\n", boot_entry_title(e
));
292 printf(" version: %s\n", e
->version
);
294 printf(" linux: %s\n", e
->kernel
);
295 if (!strv_isempty(e
->initrd
)) {
296 _cleanup_free_
char *t
;
298 t
= strv_join(e
->initrd
, " ");
302 printf(" initrd: %s\n", t
);
304 if (!strv_isempty(e
->options
)) {
305 _cleanup_free_
char *t
;
307 t
= strv_join(e
->options
, " ");
311 printf(" options: %s\n", t
);
314 printf(" devicetree: %s\n", e
->device_tree
);
321 static int compare_product(const char *a
, const char *b
) {
330 return x
< y
? -1 : x
> y
? 1 : 0;
332 return strncmp(a
, b
, x
);
335 static int compare_version(const char *a
, const char *b
) {
339 a
+= strcspn(a
, " ");
341 b
+= strcspn(b
, " ");
344 return strverscmp(a
, b
);
347 static int version_check(int fd_from
, const char *from
, int fd_to
, const char *to
) {
348 _cleanup_free_
char *a
= NULL
, *b
= NULL
;
351 assert(fd_from
>= 0);
356 r
= get_file_version(fd_from
, &a
);
360 log_error("Source file \"%s\" does not carry version information!", from
);
364 r
= get_file_version(fd_to
, &b
);
367 if (r
== 0 || compare_product(a
, b
) != 0) {
368 log_notice("Skipping \"%s\", since it's owned by another boot loader.", to
);
372 if (compare_version(a
, b
) < 0) {
373 log_warning("Skipping \"%s\", since a newer boot loader version exists already.", to
);
380 static int copy_file_with_version_check(const char *from
, const char *to
, bool force
) {
381 _cleanup_close_
int fd_from
= -1, fd_to
= -1;
382 _cleanup_free_
char *t
= NULL
;
385 fd_from
= open(from
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
);
387 return log_error_errno(errno
, "Failed to open \"%s\" for reading: %m", from
);
390 fd_to
= open(to
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
);
392 if (errno
!= -ENOENT
)
393 return log_error_errno(errno
, "Failed to open \"%s\" for reading: %m", to
);
395 r
= version_check(fd_from
, from
, fd_to
, to
);
399 if (lseek(fd_from
, 0, SEEK_SET
) == (off_t
) -1)
400 return log_error_errno(errno
, "Failed to seek in \"%s\": %m", from
);
402 fd_to
= safe_close(fd_to
);
406 r
= tempfn_random(to
, NULL
, &t
);
410 RUN_WITH_UMASK(0000) {
411 fd_to
= open(t
, O_WRONLY
|O_CREAT
|O_CLOEXEC
|O_EXCL
|O_NOFOLLOW
, 0644);
413 return log_error_errno(errno
, "Failed to open \"%s\" for writing: %m", t
);
416 r
= copy_bytes(fd_from
, fd_to
, (uint64_t) -1, COPY_REFLINK
);
419 return log_error_errno(r
, "Failed to copy data from \"%s\" to \"%s\": %m", from
, t
);
422 (void) copy_times(fd_from
, fd_to
);
424 if (fsync(fd_to
) < 0) {
425 (void) unlink_noerrno(t
);
426 return log_error_errno(errno
, "Failed to copy data from \"%s\" to \"%s\": %m", from
, t
);
429 (void) fsync_directory_of_file(fd_to
);
431 r
= renameat(AT_FDCWD
, t
, AT_FDCWD
, to
);
433 (void) unlink_noerrno(t
);
434 return log_error_errno(errno
, "Failed to rename \"%s\" to \"%s\": %m", t
, to
);
437 log_info("Copied \"%s\" to \"%s\".", from
, to
);
442 static int mkdir_one(const char *prefix
, const char *suffix
) {
445 p
= strjoina(prefix
, "/", suffix
);
446 if (mkdir(p
, 0700) < 0) {
448 return log_error_errno(errno
, "Failed to create \"%s\": %m", p
);
450 log_info("Created \"%s\".", p
);
455 static const char *efi_subdirs
[] = {
464 static int create_dirs(const char *esp_path
) {
468 STRV_FOREACH(i
, efi_subdirs
) {
469 r
= mkdir_one(esp_path
, *i
);
477 static int copy_one_file(const char *esp_path
, const char *name
, bool force
) {
481 p
= strjoina(BOOTLIBDIR
"/", name
);
482 q
= strjoina(esp_path
, "/EFI/systemd/", name
);
483 r
= copy_file_with_version_check(p
, q
, force
);
485 if (startswith(name
, "systemd-boot")) {
489 /* Create the EFI default boot loader name (specified for removable devices) */
490 v
= strjoina(esp_path
, "/EFI/BOOT/BOOT",
491 name
+ STRLEN("systemd-boot"));
492 ascii_strupper(strrchr(v
, '/') + 1);
494 k
= copy_file_with_version_check(p
, v
, force
);
502 static int install_binaries(const char *esp_path
, bool force
) {
504 _cleanup_closedir_
DIR *d
= NULL
;
508 /* Don't create any of these directories when we are
509 * just updating. When we update we'll drop-in our
510 * files (unless there are newer ones already), but we
511 * won't create the directories for them in the first
513 r
= create_dirs(esp_path
);
518 d
= opendir(BOOTLIBDIR
);
520 return log_error_errno(errno
, "Failed to open \""BOOTLIBDIR
"\": %m
");
522 FOREACH_DIRENT(de, d, break) {
525 if (!endswith_no_case(de->d_name, ".efi
"))
528 k = copy_one_file(esp_path, de->d_name, force);
536 static bool same_entry(uint16_t id, const sd_id128_t uuid, const char *path) {
537 _cleanup_free_ char *opath = NULL;
541 r = efi_get_boot_option(id, NULL, &ouuid, &opath, NULL);
544 if (!sd_id128_equal(uuid, ouuid))
546 if (!streq_ptr(path, opath))
552 static int find_slot(sd_id128_t uuid, const char *path, uint16_t *id) {
553 _cleanup_free_ uint16_t *options = NULL;
556 n = efi_get_boot_options(&options);
560 /* find already existing systemd-boot entry */
561 for (i = 0; i < n; i++)
562 if (same_entry(options[i], uuid, path)) {
567 /* find free slot in the sorted BootXXXX variable list */
568 for (i = 0; i < n; i++)
569 if (i != options[i]) {
574 /* use the next one */
581 static int insert_into_order(uint16_t slot, bool first) {
582 _cleanup_free_ uint16_t *order = NULL;
586 n = efi_get_boot_order(&order);
588 /* no entry, add us */
589 return efi_set_boot_order(&slot, 1);
591 /* are we the first and only one? */
592 if (n == 1 && order[0] == slot)
595 /* are we already in the boot order? */
596 for (i = 0; i < n; i++) {
597 if (order[i] != slot)
600 /* we do not require to be the first one, all is fine */
604 /* move us to the first slot */
605 memmove(order + 1, order, i * sizeof(uint16_t));
607 return efi_set_boot_order(order, n);
611 t = realloc(order, (n + 1) * sizeof(uint16_t));
616 /* add us to the top or end of the list */
618 memmove(order + 1, order, n * sizeof(uint16_t));
623 return efi_set_boot_order(order, n + 1);
626 static int remove_from_order(uint16_t slot) {
627 _cleanup_free_ uint16_t *order = NULL;
630 n = efi_get_boot_order(&order);
634 for (i = 0; i < n; i++) {
635 if (order[i] != slot)
639 memmove(order + i, order + i+1, (n - i) * sizeof(uint16_t));
640 return efi_set_boot_order(order, n - 1);
646 static int install_variables(const char *esp_path,
647 uint32_t part, uint64_t pstart, uint64_t psize,
648 sd_id128_t uuid, const char *path,
654 if (!is_efi_boot()) {
655 log_warning("Not booted with EFI
, skipping EFI variable setup
.");
659 p = strjoina(esp_path, path);
660 if (access(p, F_OK) < 0) {
664 return log_error_errno(errno, "Cannot access
\"%s
\": %m
", p);
667 r = find_slot(uuid, path, &slot);
669 return log_error_errno(r,
671 "Failed to access EFI variables
. Is the
\"efivarfs
\" filesystem mounted
?" :
672 "Failed to determine current boot order
: %m
");
674 if (first || r == 0) {
675 r = efi_add_boot_option(slot, "Linux Boot Manager
",
679 return log_error_errno(r, "Failed to create EFI Boot variable entry
: %m
");
681 log_info("Created EFI boot entry
\"Linux Boot Manager
\".");
684 return insert_into_order(slot, first);
687 static int remove_boot_efi(const char *esp_path) {
689 _cleanup_closedir_ DIR *d = NULL;
693 p = strjoina(esp_path, "/EFI
/BOOT
");
699 return log_error_errno(errno, "Failed to open directory
\"%s
\": %m
", p);
702 FOREACH_DIRENT(de, d, break) {
703 _cleanup_close_ int fd = -1;
704 _cleanup_free_ char *v = NULL;
706 if (!endswith_no_case(de->d_name, ".efi
"))
709 if (!startswith_no_case(de->d_name, "boot
"))
712 fd = openat(dirfd(d), de->d_name, O_RDONLY|O_CLOEXEC);
714 return log_error_errno(errno, "Failed to open
\"%s
/%s
\" for reading
: %m
", p, de->d_name);
716 r = get_file_version(fd, &v);
719 if (r > 0 && startswith(v, "systemd
-boot
")) {
720 r = unlinkat(dirfd(d), de->d_name, 0);
722 return log_error_errno(errno, "Failed to remove
\"%s
/%s
\": %m
", p, de->d_name);
724 log_info("Removed
\"%s
/%s
\".", p, de->d_name);
733 static int rmdir_one(const char *prefix, const char *suffix) {
736 p = strjoina(prefix, "/", suffix);
738 if (!IN_SET(errno, ENOENT, ENOTEMPTY))
739 return log_error_errno(errno, "Failed to remove
\"%s
\": %m
", p);
741 log_info("Removed
\"%s
\".", p);
746 static int remove_binaries(const char *esp_path) {
751 p = strjoina(esp_path, "/EFI
/systemd
");
752 r = rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
754 q = remove_boot_efi(esp_path);
758 for (i = ELEMENTSOF(efi_subdirs)-1; i > 0; i--) {
759 q = rmdir_one(esp_path, efi_subdirs[i-1]);
767 static int remove_variables(sd_id128_t uuid, const char *path, bool in_order) {
774 r = find_slot(uuid, path, &slot);
778 r = efi_remove_boot_option(slot);
783 return remove_from_order(slot);
788 static int install_loader_config(const char *esp_path) {
790 char machine_string[SD_ID128_STRING_MAX];
791 _cleanup_(unlink_and_freep) char *t = NULL;
792 _cleanup_fclose_ FILE *f = NULL;
793 sd_id128_t machine_id;
797 r = sd_id128_get_machine(&machine_id);
799 return log_error_errno(r, "Failed to get machine id
: %m
");
801 p = strjoina(esp_path, "/loader
/loader
.conf
");
803 if (access(p, F_OK) >= 0) /* Silently skip creation if the file already exists (early check) */
806 fd = open_tmpfile_linkable(p, O_WRONLY|O_CLOEXEC, &t);
808 return log_error_errno(fd, "Failed to open
\"%s
\" for writing
: %m
", p);
810 f = fdopen(fd, "we
");
816 fprintf(f, "#timeout 3\n");
817 fprintf(f, "#console-mode keep\n");
818 fprintf(f, "default %s-*\n", sd_id128_to_string(machine_id, machine_string));
820 r = fflush_sync_and_check(f);
822 return log_error_errno(r, "Failed to write \"%s\": %m", p);
824 r = link_tmpfile(fd, t, p);
826 return 0; /* Silently skip creation if the file exists now (recheck) */
828 return log_error_errno(r, "Failed to move \"%s\" into place: %m", p);
835 static int help(int argc, char *argv[], void *userdata) {
837 printf("%s [COMMAND] [OPTIONS...]\n"
839 "Install, update or remove the systemd-boot EFI boot manager.\n\n"
840 " -h --help Show this help\n"
841 " --version Print version\n"
842 " --path=PATH Path to the EFI System Partition (ESP)\n"
843 " -p --print-path Print path to the EFI partition\n"
844 " --no-variables Don't touch EFI variables\n"
847 " status Show status of installed systemd-boot and EFI variables\n"
848 " list List boot entries\n"
849 " install Install systemd-boot to the ESP and EFI variables\n"
850 " update Update systemd-boot in the ESP and EFI variables\n"
851 " remove Remove systemd-boot from the ESP and EFI variables\n",
852 program_invocation_short_name);
857 static int parse_argv(int argc, char *argv[]) {
864 static const struct option options[] = {
865 { "help", no_argument, NULL, 'h' },
866 { "version", no_argument, NULL, ARG_VERSION },
867 { "path", required_argument, NULL, ARG_PATH },
868 { "print-path", no_argument, NULL, 'p' },
869 { "no-variables", no_argument, NULL, ARG_NO_VARIABLES },
878 while ((c = getopt_long(argc, argv, "hp", options, NULL)) >= 0)
889 r = free_and_strdup(&arg_path, optarg);
895 arg_print_path = true;
898 case ARG_NO_VARIABLES:
899 arg_touch_variables = false;
906 assert_not_reached("Unknown option");
912 static void read_loader_efi_var(const char *name, char **var) {
915 r = efi_get_variable_string(EFI_VENDOR_LOADER, name, var);
916 if (r < 0 && r != -ENOENT)
917 log_warning_errno(r, "Failed to read EFI variable %s: %m", name);
920 static int verb_status(int argc, char *argv[], void *userdata) {
922 sd_id128_t uuid = SD_ID128_NULL;
925 r = acquire_esp(geteuid() != 0, NULL, NULL, NULL, &uuid);
927 if (arg_print_path) {
928 if (r == -EACCES) /* If we couldn't acquire the ESP path, log about access errors (which is the only
929 * error the
find_esp_and_warn() won
't log on its own) */
930 return log_error_errno(r, "Failed to determine ESP: %m");
938 r = 0; /* If we couldn't determine the path
, then don
't consider that a problem from here on, just show what we
942 _cleanup_free_ char *fw_type = NULL, *fw_info = NULL, *loader = NULL, *loader_path = NULL, *stub = NULL;
943 sd_id128_t loader_part_uuid = SD_ID128_NULL;
945 read_loader_efi_var("LoaderFirmwareType", &fw_type);
946 read_loader_efi_var("LoaderFirmwareInfo", &fw_info);
947 read_loader_efi_var("LoaderInfo", &loader);
948 read_loader_efi_var("StubInfo", &stub);
949 read_loader_efi_var("LoaderImageIdentifier", &loader_path);
952 efi_tilt_backslashes(loader_path);
954 k = efi_loader_get_device_part_uuid(&loader_part_uuid);
955 if (k < 0 && k != -ENOENT)
956 r = log_warning_errno(k, "Failed to read EFI variable LoaderDevicePartUUID: %m");
959 printf(" Firmware: %s (%s)\n", strna(fw_type), strna(fw_info));
961 k = is_efi_secure_boot();
963 r = log_warning_errno(k, "Failed to query secure boot status: %m");
965 printf(" Secure Boot: %sd\n", enable_disable(k));
967 k = is_efi_secure_boot_setup_mode();
969 r = log_warning_errno(k, "Failed to query secure boot mode: %m");
971 printf(" Setup Mode: %s\n", k ? "setup" : "user");
974 printf("Current Loader:\n");
975 printf(" Product: %s\n", strna(loader));
977 printf(" Stub: %s\n", stub);
978 if (!sd_id128_is_null(loader_part_uuid))
979 printf(" ESP: /dev/disk/by-partuuid/%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
980 SD_ID128_FORMAT_VAL(loader_part_uuid));
982 printf(" ESP: n/a\n");
983 printf(" File: %s%s\n", special_glyph(TREE_RIGHT), strna(loader_path));
986 printf("System:\n Not booted with EFI\n\n");
989 k = status_binaries(arg_path, uuid);
995 k = status_variables();
1001 k = status_entries(arg_path, uuid);
1009 static int verb_list(int argc, char *argv[], void *userdata) {
1010 _cleanup_(boot_config_free) BootConfig config = {};
1011 sd_id128_t uuid = SD_ID128_NULL;
1015 /* If we lack privileges we invoke find_esp_and_warn() in "unprivileged mode" here, which does two things: turn
1016 * off logging about access errors and turn off potentially privileged device probing. Here we're interested in
1017 * the latter but
not the former
, hence request the mode
, and log about EACCES
. */
1019 r
= acquire_esp(geteuid() != 0, NULL
, NULL
, NULL
, &uuid
);
1020 if (r
== -EACCES
) /* We really need the ESP path for this call, hence also log about access errors */
1021 return log_error_errno(r
, "Failed to determine ESP: %m");
1025 r
= boot_entries_load_config(arg_path
, &config
);
1027 return log_error_errno(r
, "Failed to load bootspec config from \"%s/loader\": %m",
1030 printf("Available boot entries:\n");
1032 for (n
= 0; n
< config
.n_entries
; n
++) {
1033 const BootEntry
*e
= &config
.entries
[n
];
1035 printf(" title: %s%s%s%s%s%s\n",
1037 boot_entry_title(e
),
1039 ansi_highlight_green(),
1040 n
== (unsigned) config
.default_entry
? " (default)" : "",
1043 printf(" version: %s\n", e
->version
);
1045 printf(" machine-id: %s\n", e
->machine_id
);
1046 if (e
->architecture
)
1047 printf(" architecture: %s\n", e
->architecture
);
1049 printf(" linux: %s\n", e
->kernel
);
1050 if (!strv_isempty(e
->initrd
)) {
1051 _cleanup_free_
char *t
;
1053 t
= strv_join(e
->initrd
, " ");
1057 printf(" initrd: %s\n", t
);
1059 if (!strv_isempty(e
->options
)) {
1060 _cleanup_free_
char *t
;
1062 t
= strv_join(e
->options
, " ");
1066 printf(" options: %s\n", t
);
1069 printf(" devicetree: %s\n", e
->device_tree
);
1077 static int verb_install(int argc
, char *argv
[], void *userdata
) {
1079 sd_id128_t uuid
= SD_ID128_NULL
;
1080 uint64_t pstart
= 0, psize
= 0;
1085 r
= acquire_esp(false, &part
, &pstart
, &psize
, &uuid
);
1089 install
= streq(argv
[0], "install");
1091 RUN_WITH_UMASK(0002) {
1092 r
= install_binaries(arg_path
, install
);
1097 r
= install_loader_config(arg_path
);
1103 if (arg_touch_variables
)
1104 r
= install_variables(arg_path
,
1105 part
, pstart
, psize
, uuid
,
1106 "/EFI/systemd/systemd-boot" EFI_MACHINE_TYPE_NAME
".efi",
1112 static int verb_remove(int argc
, char *argv
[], void *userdata
) {
1113 sd_id128_t uuid
= SD_ID128_NULL
;
1116 r
= acquire_esp(false, NULL
, NULL
, NULL
, &uuid
);
1120 r
= remove_binaries(arg_path
);
1122 if (arg_touch_variables
) {
1125 q
= remove_variables(uuid
, "/EFI/systemd/systemd-boot" EFI_MACHINE_TYPE_NAME
".efi", true);
1126 if (q
< 0 && r
== 0)
1133 static int bootctl_main(int argc
, char *argv
[]) {
1135 static const Verb verbs
[] = {
1136 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
1137 { "status", VERB_ANY
, 1, VERB_DEFAULT
, verb_status
},
1138 { "list", VERB_ANY
, 1, 0, verb_list
},
1139 { "install", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_install
},
1140 { "update", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_install
},
1141 { "remove", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_remove
},
1145 return dispatch_verb(argc
, argv
, verbs
, NULL
);
1148 int main(int argc
, char *argv
[]) {
1151 log_parse_environment();
1154 /* If we run in a container, automatically turn of EFI file system access */
1155 if (detect_container() > 0)
1156 arg_touch_variables
= false;
1158 r
= parse_argv(argc
, argv
);
1162 r
= bootctl_main(argc
, argv
);
1166 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;