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 if (renameat(AT_FDCWD
, t
, AT_FDCWD
, to
) < 0) {
432 (void) unlink_noerrno(t
);
433 return log_error_errno(errno
, "Failed to rename \"%s\" to \"%s\": %m", t
, to
);
436 log_info("Copied \"%s\" to \"%s\".", from
, to
);
441 static int mkdir_one(const char *prefix
, const char *suffix
) {
444 p
= strjoina(prefix
, "/", suffix
);
445 if (mkdir(p
, 0700) < 0) {
447 return log_error_errno(errno
, "Failed to create \"%s\": %m", p
);
449 log_info("Created \"%s\".", p
);
454 static const char *efi_subdirs
[] = {
463 static int create_dirs(const char *esp_path
) {
467 STRV_FOREACH(i
, efi_subdirs
) {
468 r
= mkdir_one(esp_path
, *i
);
476 static int copy_one_file(const char *esp_path
, const char *name
, bool force
) {
480 p
= strjoina(BOOTLIBDIR
"/", name
);
481 q
= strjoina(esp_path
, "/EFI/systemd/", name
);
482 r
= copy_file_with_version_check(p
, q
, force
);
484 if (startswith(name
, "systemd-boot")) {
488 /* Create the EFI default boot loader name (specified for removable devices) */
489 v
= strjoina(esp_path
, "/EFI/BOOT/BOOT",
490 name
+ STRLEN("systemd-boot"));
491 ascii_strupper(strrchr(v
, '/') + 1);
493 k
= copy_file_with_version_check(p
, v
, force
);
501 static int install_binaries(const char *esp_path
, bool force
) {
503 _cleanup_closedir_
DIR *d
= NULL
;
507 /* Don't create any of these directories when we are
508 * just updating. When we update we'll drop-in our
509 * files (unless there are newer ones already), but we
510 * won't create the directories for them in the first
512 r
= create_dirs(esp_path
);
517 d
= opendir(BOOTLIBDIR
);
519 return log_error_errno(errno
, "Failed to open \""BOOTLIBDIR
"\": %m
");
521 FOREACH_DIRENT(de, d, break) {
524 if (!endswith_no_case(de->d_name, ".efi
"))
527 k = copy_one_file(esp_path, de->d_name, force);
535 static bool same_entry(uint16_t id, const sd_id128_t uuid, const char *path) {
536 _cleanup_free_ char *opath = NULL;
540 r = efi_get_boot_option(id, NULL, &ouuid, &opath, NULL);
543 if (!sd_id128_equal(uuid, ouuid))
545 if (!streq_ptr(path, opath))
551 static int find_slot(sd_id128_t uuid, const char *path, uint16_t *id) {
552 _cleanup_free_ uint16_t *options = NULL;
555 n = efi_get_boot_options(&options);
559 /* find already existing systemd-boot entry */
560 for (i = 0; i < n; i++)
561 if (same_entry(options[i], uuid, path)) {
566 /* find free slot in the sorted BootXXXX variable list */
567 for (i = 0; i < n; i++)
568 if (i != options[i]) {
573 /* use the next one */
580 static int insert_into_order(uint16_t slot, bool first) {
581 _cleanup_free_ uint16_t *order = NULL;
585 n = efi_get_boot_order(&order);
587 /* no entry, add us */
588 return efi_set_boot_order(&slot, 1);
590 /* are we the first and only one? */
591 if (n == 1 && order[0] == slot)
594 /* are we already in the boot order? */
595 for (i = 0; i < n; i++) {
596 if (order[i] != slot)
599 /* we do not require to be the first one, all is fine */
603 /* move us to the first slot */
604 memmove(order + 1, order, i * sizeof(uint16_t));
606 return efi_set_boot_order(order, n);
610 t = realloc(order, (n + 1) * sizeof(uint16_t));
615 /* add us to the top or end of the list */
617 memmove(order + 1, order, n * sizeof(uint16_t));
622 return efi_set_boot_order(order, n + 1);
625 static int remove_from_order(uint16_t slot) {
626 _cleanup_free_ uint16_t *order = NULL;
629 n = efi_get_boot_order(&order);
633 for (i = 0; i < n; i++) {
634 if (order[i] != slot)
638 memmove(order + i, order + i+1, (n - i) * sizeof(uint16_t));
639 return efi_set_boot_order(order, n - 1);
645 static int install_variables(const char *esp_path,
646 uint32_t part, uint64_t pstart, uint64_t psize,
647 sd_id128_t uuid, const char *path,
653 if (!is_efi_boot()) {
654 log_warning("Not booted with EFI
, skipping EFI variable setup
.");
658 p = strjoina(esp_path, path);
659 if (access(p, F_OK) < 0) {
663 return log_error_errno(errno, "Cannot access
\"%s
\": %m
", p);
666 r = find_slot(uuid, path, &slot);
668 return log_error_errno(r,
670 "Failed to access EFI variables
. Is the
\"efivarfs
\" filesystem mounted
?" :
671 "Failed to determine current boot order
: %m
");
673 if (first || r == 0) {
674 r = efi_add_boot_option(slot, "Linux Boot Manager
",
678 return log_error_errno(r, "Failed to create EFI Boot variable entry
: %m
");
680 log_info("Created EFI boot entry
\"Linux Boot Manager
\".");
683 return insert_into_order(slot, first);
686 static int remove_boot_efi(const char *esp_path) {
688 _cleanup_closedir_ DIR *d = NULL;
692 p = strjoina(esp_path, "/EFI
/BOOT
");
698 return log_error_errno(errno, "Failed to open directory
\"%s
\": %m
", p);
701 FOREACH_DIRENT(de, d, break) {
702 _cleanup_close_ int fd = -1;
703 _cleanup_free_ char *v = NULL;
705 if (!endswith_no_case(de->d_name, ".efi
"))
708 if (!startswith_no_case(de->d_name, "boot
"))
711 fd = openat(dirfd(d), de->d_name, O_RDONLY|O_CLOEXEC);
713 return log_error_errno(errno, "Failed to open
\"%s
/%s
\" for reading
: %m
", p, de->d_name);
715 r = get_file_version(fd, &v);
718 if (r > 0 && startswith(v, "systemd
-boot
")) {
719 r = unlinkat(dirfd(d), de->d_name, 0);
721 return log_error_errno(errno, "Failed to remove
\"%s
/%s
\": %m
", p, de->d_name);
723 log_info("Removed
\"%s
/%s
\".", p, de->d_name);
732 static int rmdir_one(const char *prefix, const char *suffix) {
735 p = strjoina(prefix, "/", suffix);
737 if (!IN_SET(errno, ENOENT, ENOTEMPTY))
738 return log_error_errno(errno, "Failed to remove
\"%s
\": %m
", p);
740 log_info("Removed
\"%s
\".", p);
745 static int remove_binaries(const char *esp_path) {
750 p = strjoina(esp_path, "/EFI
/systemd
");
751 r = rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
753 q = remove_boot_efi(esp_path);
757 for (i = ELEMENTSOF(efi_subdirs)-1; i > 0; i--) {
758 q = rmdir_one(esp_path, efi_subdirs[i-1]);
766 static int remove_variables(sd_id128_t uuid, const char *path, bool in_order) {
773 r = find_slot(uuid, path, &slot);
777 r = efi_remove_boot_option(slot);
782 return remove_from_order(slot);
787 static int install_loader_config(const char *esp_path) {
789 char machine_string[SD_ID128_STRING_MAX];
790 _cleanup_(unlink_and_freep) char *t = NULL;
791 _cleanup_fclose_ FILE *f = NULL;
792 sd_id128_t machine_id;
796 r = sd_id128_get_machine(&machine_id);
798 return log_error_errno(r, "Failed to get machine id
: %m
");
800 p = strjoina(esp_path, "/loader
/loader
.conf
");
802 if (access(p, F_OK) >= 0) /* Silently skip creation if the file already exists (early check) */
805 fd = open_tmpfile_linkable(p, O_WRONLY|O_CLOEXEC, &t);
807 return log_error_errno(fd, "Failed to open
\"%s
\" for writing
: %m
", p);
809 f = fdopen(fd, "we
");
815 fprintf(f, "#timeout 3\n");
816 fprintf(f, "#console-mode keep\n");
817 fprintf(f, "default %s-*\n", sd_id128_to_string(machine_id, machine_string));
819 r = fflush_sync_and_check(f);
821 return log_error_errno(r, "Failed to write \"%s\": %m", p);
823 r = link_tmpfile(fd, t, p);
825 return 0; /* Silently skip creation if the file exists now (recheck) */
827 return log_error_errno(r, "Failed to move \"%s\" into place: %m", p);
834 static int help(int argc, char *argv[], void *userdata) {
836 printf("%s [COMMAND] [OPTIONS...]\n"
838 "Install, update or remove the systemd-boot EFI boot manager.\n\n"
839 " -h --help Show this help\n"
840 " --version Print version\n"
841 " --path=PATH Path to the EFI System Partition (ESP)\n"
842 " -p --print-path Print path to the EFI partition\n"
843 " --no-variables Don't touch EFI variables\n"
846 " status Show status of installed systemd-boot and EFI variables\n"
847 " list List boot entries\n"
848 " install Install systemd-boot to the ESP and EFI variables\n"
849 " update Update systemd-boot in the ESP and EFI variables\n"
850 " remove Remove systemd-boot from the ESP and EFI variables\n",
851 program_invocation_short_name);
856 static int parse_argv(int argc, char *argv[]) {
863 static const struct option options[] = {
864 { "help", no_argument, NULL, 'h' },
865 { "version", no_argument, NULL, ARG_VERSION },
866 { "path", required_argument, NULL, ARG_PATH },
867 { "print-path", no_argument, NULL, 'p' },
868 { "no-variables", no_argument, NULL, ARG_NO_VARIABLES },
877 while ((c = getopt_long(argc, argv, "hp", options, NULL)) >= 0)
888 r = free_and_strdup(&arg_path, optarg);
894 arg_print_path = true;
897 case ARG_NO_VARIABLES:
898 arg_touch_variables = false;
905 assert_not_reached("Unknown option");
911 static void read_loader_efi_var(const char *name, char **var) {
914 r = efi_get_variable_string(EFI_VENDOR_LOADER, name, var);
915 if (r < 0 && r != -ENOENT)
916 log_warning_errno(r, "Failed to read EFI variable %s: %m", name);
919 static int verb_status(int argc, char *argv[], void *userdata) {
921 sd_id128_t uuid = SD_ID128_NULL;
924 r = acquire_esp(geteuid() != 0, NULL, NULL, NULL, &uuid);
926 if (arg_print_path) {
927 if (r == -EACCES) /* If we couldn't acquire the ESP path, log about access errors (which is the only
928 * error the
find_esp_and_warn() won
't log on its own) */
929 return log_error_errno(r, "Failed to determine ESP: %m");
937 r = 0; /* If we couldn't determine the path
, then don
't consider that a problem from here on, just show what we
941 _cleanup_free_ char *fw_type = NULL, *fw_info = NULL, *loader = NULL, *loader_path = NULL, *stub = NULL;
942 sd_id128_t loader_part_uuid = SD_ID128_NULL;
944 read_loader_efi_var("LoaderFirmwareType", &fw_type);
945 read_loader_efi_var("LoaderFirmwareInfo", &fw_info);
946 read_loader_efi_var("LoaderInfo", &loader);
947 read_loader_efi_var("StubInfo", &stub);
948 read_loader_efi_var("LoaderImageIdentifier", &loader_path);
951 efi_tilt_backslashes(loader_path);
953 k = efi_loader_get_device_part_uuid(&loader_part_uuid);
954 if (k < 0 && k != -ENOENT)
955 r = log_warning_errno(k, "Failed to read EFI variable LoaderDevicePartUUID: %m");
958 printf(" Firmware: %s (%s)\n", strna(fw_type), strna(fw_info));
960 k = is_efi_secure_boot();
962 r = log_warning_errno(k, "Failed to query secure boot status: %m");
964 printf(" Secure Boot: %sd\n", enable_disable(k));
966 k = is_efi_secure_boot_setup_mode();
968 r = log_warning_errno(k, "Failed to query secure boot mode: %m");
970 printf(" Setup Mode: %s\n", k ? "setup" : "user");
973 printf("Current Loader:\n");
974 printf(" Product: %s\n", strna(loader));
976 printf(" Stub: %s\n", stub);
977 if (!sd_id128_is_null(loader_part_uuid))
978 printf(" ESP: /dev/disk/by-partuuid/%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
979 SD_ID128_FORMAT_VAL(loader_part_uuid));
981 printf(" ESP: n/a\n");
982 printf(" File: %s%s\n", special_glyph(TREE_RIGHT), strna(loader_path));
985 printf("System:\n Not booted with EFI\n\n");
988 k = status_binaries(arg_path, uuid);
994 k = status_variables();
1000 k = status_entries(arg_path, uuid);
1008 static int verb_list(int argc, char *argv[], void *userdata) {
1009 _cleanup_(boot_config_free) BootConfig config = {};
1010 sd_id128_t uuid = SD_ID128_NULL;
1014 /* If we lack privileges we invoke find_esp_and_warn() in "unprivileged mode" here, which does two things: turn
1015 * off logging about access errors and turn off potentially privileged device probing. Here we're interested in
1016 * the latter but
not the former
, hence request the mode
, and log about EACCES
. */
1018 r
= acquire_esp(geteuid() != 0, NULL
, NULL
, NULL
, &uuid
);
1019 if (r
== -EACCES
) /* We really need the ESP path for this call, hence also log about access errors */
1020 return log_error_errno(r
, "Failed to determine ESP: %m");
1024 r
= boot_entries_load_config(arg_path
, &config
);
1026 return log_error_errno(r
, "Failed to load bootspec config from \"%s/loader\": %m",
1029 printf("Available boot entries:\n");
1031 for (n
= 0; n
< config
.n_entries
; n
++) {
1032 const BootEntry
*e
= &config
.entries
[n
];
1034 printf(" title: %s%s%s%s%s%s\n",
1036 boot_entry_title(e
),
1038 ansi_highlight_green(),
1039 n
== (unsigned) config
.default_entry
? " (default)" : "",
1042 printf(" version: %s\n", e
->version
);
1044 printf(" machine-id: %s\n", e
->machine_id
);
1045 if (e
->architecture
)
1046 printf(" architecture: %s\n", e
->architecture
);
1048 printf(" linux: %s\n", e
->kernel
);
1049 if (!strv_isempty(e
->initrd
)) {
1050 _cleanup_free_
char *t
;
1052 t
= strv_join(e
->initrd
, " ");
1056 printf(" initrd: %s\n", t
);
1058 if (!strv_isempty(e
->options
)) {
1059 _cleanup_free_
char *t
;
1061 t
= strv_join(e
->options
, " ");
1065 printf(" options: %s\n", t
);
1068 printf(" devicetree: %s\n", e
->device_tree
);
1076 static int verb_install(int argc
, char *argv
[], void *userdata
) {
1078 sd_id128_t uuid
= SD_ID128_NULL
;
1079 uint64_t pstart
= 0, psize
= 0;
1084 r
= acquire_esp(false, &part
, &pstart
, &psize
, &uuid
);
1088 install
= streq(argv
[0], "install");
1090 RUN_WITH_UMASK(0002) {
1091 r
= install_binaries(arg_path
, install
);
1096 r
= install_loader_config(arg_path
);
1102 if (arg_touch_variables
)
1103 r
= install_variables(arg_path
,
1104 part
, pstart
, psize
, uuid
,
1105 "/EFI/systemd/systemd-boot" EFI_MACHINE_TYPE_NAME
".efi",
1111 static int verb_remove(int argc
, char *argv
[], void *userdata
) {
1112 sd_id128_t uuid
= SD_ID128_NULL
;
1115 r
= acquire_esp(false, NULL
, NULL
, NULL
, &uuid
);
1119 r
= remove_binaries(arg_path
);
1121 if (arg_touch_variables
) {
1124 q
= remove_variables(uuid
, "/EFI/systemd/systemd-boot" EFI_MACHINE_TYPE_NAME
".efi", true);
1125 if (q
< 0 && r
== 0)
1132 static int bootctl_main(int argc
, char *argv
[]) {
1134 static const Verb verbs
[] = {
1135 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
1136 { "status", VERB_ANY
, 1, VERB_DEFAULT
, verb_status
},
1137 { "list", VERB_ANY
, 1, 0, verb_list
},
1138 { "install", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_install
},
1139 { "update", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_install
},
1140 { "remove", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_remove
},
1144 return dispatch_verb(argc
, argv
, verbs
, NULL
);
1147 int main(int argc
, char *argv
[]) {
1150 log_parse_environment();
1153 /* If we run in a container, automatically turn of EFI file system access */
1154 if (detect_container() > 0)
1155 arg_touch_variables
= false;
1157 r
= parse_argv(argc
, argv
);
1161 r
= bootctl_main(argc
, argv
);
1165 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;