1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2013-2015 Kay Sievers
4 Copyright 2013 Lennart Poettering
14 #include <linux/magic.h>
21 #include <sys/statfs.h>
26 #include "alloc-util.h"
27 #include "blkid-util.h"
30 #include "dirent-util.h"
35 #include "locale-util.h"
36 #include "parse-util.h"
38 #include "stat-util.h"
39 #include "string-util.h"
41 #include "terminal-util.h"
42 #include "umask-util.h"
47 static char *arg_path
= NULL
;
48 static bool arg_print_path
= false;
49 static bool arg_touch_variables
= true;
51 static int acquire_esp(
52 bool unprivileged_mode
,
56 sd_id128_t
*ret_uuid
) {
61 /* Find the ESP, and log about errors. Note that find_esp_and_warn() will log in all error cases on its own,
62 * except for ENOKEY (which is good, we want to show our own message in that case, suggesting use of --path=)
63 * and EACCESS (only when we request unprivileged mode; in this case we simply eat up the error here, so that
64 * --list and --status work too, without noise about this). */
66 r
= find_esp_and_warn(arg_path
, unprivileged_mode
, &np
, ret_part
, ret_pstart
, ret_psize
, ret_uuid
);
68 return log_error_errno(r
,
69 "Couldn't find EFI system partition. It is recommended to mount it to /boot or /efi.\n"
70 "Alternatively, use --path= to specify path to mount point.");
74 free_and_replace(arg_path
, np
);
76 log_debug("Using EFI System Partition at %s.", arg_path
);
81 /* search for "#### LoaderInfo: systemd-boot 218 ####" string inside the binary */
82 static int get_file_version(int fd
, char **v
) {
92 if (fstat(fd
, &st
) < 0)
93 return log_error_errno(errno
, "Failed to stat EFI binary: %m");
95 if (st
.st_size
< 27) {
100 buf
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
101 if (buf
== MAP_FAILED
)
102 return log_error_errno(errno
, "Failed to memory map EFI binary: %m");
104 s
= memmem(buf
, st
.st_size
- 8, "#### LoaderInfo: ", 17);
109 e
= memmem(s
, st
.st_size
- (s
- buf
), " ####", 5);
110 if (!e
|| e
- s
< 3) {
111 log_error("Malformed version string.");
116 x
= strndup(s
, e
- s
);
124 (void) munmap(buf
, st
.st_size
);
129 static int enumerate_binaries(const char *esp_path
, const char *path
, const char *prefix
) {
131 _cleanup_closedir_
DIR *d
= NULL
;
135 p
= strjoina(esp_path
, "/", path
);
141 return log_error_errno(errno
, "Failed to read \"%s\": %m", p
);
144 FOREACH_DIRENT(de
, d
, break) {
145 _cleanup_close_
int fd
= -1;
146 _cleanup_free_
char *v
= NULL
;
148 if (!endswith_no_case(de
->d_name
, ".efi"))
151 if (prefix
&& !startswith_no_case(de
->d_name
, prefix
))
154 fd
= openat(dirfd(d
), de
->d_name
, O_RDONLY
|O_CLOEXEC
);
156 return log_error_errno(errno
, "Failed to open \"%s/%s\" for reading: %m", p
, de
->d_name
);
158 r
= get_file_version(fd
, &v
);
162 printf(" File: %s/%s/%s (%s)\n", special_glyph(TREE_RIGHT
), path
, de
->d_name
, v
);
164 printf(" File: %s/%s/%s\n", special_glyph(TREE_RIGHT
), path
, de
->d_name
);
171 static int status_binaries(const char *esp_path
, sd_id128_t partition
) {
174 printf("Boot Loader Binaries:\n");
177 printf(" ESP: Cannot find or access mount point of ESP.\n\n");
181 printf(" ESP: %s", esp_path
);
182 if (!sd_id128_is_null(partition
))
183 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
));
186 r
= enumerate_binaries(esp_path
, "EFI/systemd", NULL
);
188 log_error("systemd-boot not installed in ESP.");
192 r
= enumerate_binaries(esp_path
, "EFI/BOOT", "boot");
194 log_error("No default/fallback boot loader installed in ESP.");
203 static int print_efi_option(uint16_t id
, bool in_order
) {
204 _cleanup_free_
char *title
= NULL
;
205 _cleanup_free_
char *path
= NULL
;
206 sd_id128_t partition
;
210 r
= efi_get_boot_option(id
, &title
, &partition
, &path
, &active
);
214 /* print only configured entries with partition information */
215 if (!path
|| sd_id128_is_null(partition
))
218 efi_tilt_backslashes(path
);
220 printf(" Title: %s\n", strna(title
));
221 printf(" ID: 0x%04X\n", id
);
222 printf(" Status: %sactive%s\n", active
? "" : "in", in_order
? ", boot-order" : "");
223 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
));
224 printf(" File: %s%s\n", special_glyph(TREE_RIGHT
), path
);
230 static int status_variables(void) {
231 int n_options
, n_order
;
232 _cleanup_free_
uint16_t *options
= NULL
, *order
= NULL
;
235 n_options
= efi_get_boot_options(&options
);
236 if (n_options
== -ENOENT
)
237 return log_error_errno(n_options
,
238 "Failed to access EFI variables, efivarfs"
239 " needs to be available at /sys/firmware/efi/efivars/.");
241 return log_error_errno(n_options
, "Failed to read EFI boot entries: %m");
243 n_order
= efi_get_boot_order(&order
);
244 if (n_order
== -ENOENT
)
246 else if (n_order
< 0)
247 return log_error_errno(n_order
, "Failed to read EFI boot order.");
249 /* print entries in BootOrder first */
250 printf("Boot Loader Entries in EFI Variables:\n");
251 for (i
= 0; i
< n_order
; i
++)
252 print_efi_option(order
[i
], true);
254 /* print remaining entries */
255 for (i
= 0; i
< n_options
; i
++) {
258 for (j
= 0; j
< n_order
; j
++)
259 if (options
[i
] == order
[j
])
262 print_efi_option(options
[i
], false);
271 static int status_entries(const char *esp_path
, sd_id128_t partition
) {
274 _cleanup_(boot_config_free
) BootConfig config
= {};
276 printf("Default Boot Entry:\n");
278 r
= boot_entries_load_config(esp_path
, &config
);
280 return log_error_errno(r
, "Failed to load bootspec config from \"%s/loader\": %m",
283 if (config
.default_entry
< 0)
284 printf("%zu entries, no entry suitable as default\n", config
.n_entries
);
286 const BootEntry
*e
= &config
.entries
[config
.default_entry
];
288 printf(" title: %s\n", boot_entry_title(e
));
290 printf(" version: %s\n", e
->version
);
292 printf(" linux: %s\n", e
->kernel
);
293 if (!strv_isempty(e
->initrd
)) {
294 _cleanup_free_
char *t
;
296 t
= strv_join(e
->initrd
, " ");
300 printf(" initrd: %s\n", t
);
302 if (!strv_isempty(e
->options
)) {
303 _cleanup_free_
char *t
;
305 t
= strv_join(e
->options
, " ");
309 printf(" options: %s\n", t
);
312 printf(" devicetree: %s\n", e
->device_tree
);
319 static int compare_product(const char *a
, const char *b
) {
328 return x
< y
? -1 : x
> y
? 1 : 0;
330 return strncmp(a
, b
, x
);
333 static int compare_version(const char *a
, const char *b
) {
337 a
+= strcspn(a
, " ");
339 b
+= strcspn(b
, " ");
342 return strverscmp(a
, b
);
345 static int version_check(int fd_from
, const char *from
, int fd_to
, const char *to
) {
346 _cleanup_free_
char *a
= NULL
, *b
= NULL
;
349 assert(fd_from
>= 0);
354 r
= get_file_version(fd_from
, &a
);
358 log_error("Source file \"%s\" does not carry version information!", from
);
362 r
= get_file_version(fd_to
, &b
);
365 if (r
== 0 || compare_product(a
, b
) != 0) {
366 log_notice("Skipping \"%s\", since it's owned by another boot loader.", to
);
370 if (compare_version(a
, b
) < 0) {
371 log_warning("Skipping \"%s\", since a newer boot loader version exists already.", to
);
378 static int copy_file_with_version_check(const char *from
, const char *to
, bool force
) {
379 _cleanup_close_
int fd_from
= -1, fd_to
= -1;
380 _cleanup_free_
char *t
= NULL
;
383 fd_from
= open(from
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
);
385 return log_error_errno(errno
, "Failed to open \"%s\" for reading: %m", from
);
388 fd_to
= open(to
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
);
390 if (errno
!= -ENOENT
)
391 return log_error_errno(errno
, "Failed to open \"%s\" for reading: %m", to
);
393 r
= version_check(fd_from
, from
, fd_to
, to
);
397 if (lseek(fd_from
, 0, SEEK_SET
) == (off_t
) -1)
398 return log_error_errno(errno
, "Failed to seek in \"%s\": %m", from
);
400 fd_to
= safe_close(fd_to
);
404 r
= tempfn_random(to
, NULL
, &t
);
408 RUN_WITH_UMASK(0000) {
409 fd_to
= open(t
, O_WRONLY
|O_CREAT
|O_CLOEXEC
|O_EXCL
|O_NOFOLLOW
, 0644);
411 return log_error_errno(errno
, "Failed to open \"%s\" for writing: %m", t
);
414 r
= copy_bytes(fd_from
, fd_to
, (uint64_t) -1, COPY_REFLINK
);
417 return log_error_errno(r
, "Failed to copy data from \"%s\" to \"%s\": %m", from
, t
);
420 (void) copy_times(fd_from
, fd_to
);
422 if (fsync(fd_to
) < 0) {
423 (void) unlink_noerrno(t
);
424 return log_error_errno(errno
, "Failed to copy data from \"%s\" to \"%s\": %m", from
, t
);
427 (void) fsync_directory_of_file(fd_to
);
429 if (renameat(AT_FDCWD
, t
, AT_FDCWD
, to
) < 0) {
430 (void) unlink_noerrno(t
);
431 return log_error_errno(errno
, "Failed to rename \"%s\" to \"%s\": %m", t
, to
);
434 log_info("Copied \"%s\" to \"%s\".", from
, to
);
439 static int mkdir_one(const char *prefix
, const char *suffix
) {
442 p
= strjoina(prefix
, "/", suffix
);
443 if (mkdir(p
, 0700) < 0) {
445 return log_error_errno(errno
, "Failed to create \"%s\": %m", p
);
447 log_info("Created \"%s\".", p
);
452 static const char *efi_subdirs
[] = {
461 static int create_dirs(const char *esp_path
) {
465 STRV_FOREACH(i
, efi_subdirs
) {
466 r
= mkdir_one(esp_path
, *i
);
474 static int copy_one_file(const char *esp_path
, const char *name
, bool force
) {
478 p
= strjoina(BOOTLIBDIR
"/", name
);
479 q
= strjoina(esp_path
, "/EFI/systemd/", name
);
480 r
= copy_file_with_version_check(p
, q
, force
);
482 if (startswith(name
, "systemd-boot")) {
486 /* Create the EFI default boot loader name (specified for removable devices) */
487 v
= strjoina(esp_path
, "/EFI/BOOT/BOOT",
488 name
+ STRLEN("systemd-boot"));
489 ascii_strupper(strrchr(v
, '/') + 1);
491 k
= copy_file_with_version_check(p
, v
, force
);
499 static int install_binaries(const char *esp_path
, bool force
) {
501 _cleanup_closedir_
DIR *d
= NULL
;
505 /* Don't create any of these directories when we are
506 * just updating. When we update we'll drop-in our
507 * files (unless there are newer ones already), but we
508 * won't create the directories for them in the first
510 r
= create_dirs(esp_path
);
515 d
= opendir(BOOTLIBDIR
);
517 return log_error_errno(errno
, "Failed to open \""BOOTLIBDIR
"\": %m
");
519 FOREACH_DIRENT(de, d, break) {
522 if (!endswith_no_case(de->d_name, ".efi
"))
525 k = copy_one_file(esp_path, de->d_name, force);
533 static bool same_entry(uint16_t id, const sd_id128_t uuid, const char *path) {
534 _cleanup_free_ char *opath = NULL;
538 r = efi_get_boot_option(id, NULL, &ouuid, &opath, NULL);
541 if (!sd_id128_equal(uuid, ouuid))
543 if (!streq_ptr(path, opath))
549 static int find_slot(sd_id128_t uuid, const char *path, uint16_t *id) {
550 _cleanup_free_ uint16_t *options = NULL;
553 n = efi_get_boot_options(&options);
557 /* find already existing systemd-boot entry */
558 for (i = 0; i < n; i++)
559 if (same_entry(options[i], uuid, path)) {
564 /* find free slot in the sorted BootXXXX variable list */
565 for (i = 0; i < n; i++)
566 if (i != options[i]) {
571 /* use the next one */
578 static int insert_into_order(uint16_t slot, bool first) {
579 _cleanup_free_ uint16_t *order = NULL;
583 n = efi_get_boot_order(&order);
585 /* no entry, add us */
586 return efi_set_boot_order(&slot, 1);
588 /* are we the first and only one? */
589 if (n == 1 && order[0] == slot)
592 /* are we already in the boot order? */
593 for (i = 0; i < n; i++) {
594 if (order[i] != slot)
597 /* we do not require to be the first one, all is fine */
601 /* move us to the first slot */
602 memmove(order + 1, order, i * sizeof(uint16_t));
604 return efi_set_boot_order(order, n);
608 t = realloc(order, (n + 1) * sizeof(uint16_t));
613 /* add us to the top or end of the list */
615 memmove(order + 1, order, n * sizeof(uint16_t));
620 return efi_set_boot_order(order, n + 1);
623 static int remove_from_order(uint16_t slot) {
624 _cleanup_free_ uint16_t *order = NULL;
627 n = efi_get_boot_order(&order);
631 for (i = 0; i < n; i++) {
632 if (order[i] != slot)
636 memmove(order + i, order + i+1, (n - i) * sizeof(uint16_t));
637 return efi_set_boot_order(order, n - 1);
643 static int install_variables(const char *esp_path,
644 uint32_t part, uint64_t pstart, uint64_t psize,
645 sd_id128_t uuid, const char *path,
651 if (!is_efi_boot()) {
652 log_warning("Not booted with EFI
, skipping EFI variable setup
.");
656 p = strjoina(esp_path, path);
657 if (access(p, F_OK) < 0) {
661 return log_error_errno(errno, "Cannot access
\"%s
\": %m
", p);
664 r = find_slot(uuid, path, &slot);
666 return log_error_errno(r,
668 "Failed to access EFI variables
. Is the
\"efivarfs
\" filesystem mounted
?" :
669 "Failed to determine current boot order
: %m
");
671 if (first || r == 0) {
672 r = efi_add_boot_option(slot, "Linux Boot Manager
",
676 return log_error_errno(r, "Failed to create EFI Boot variable entry
: %m
");
678 log_info("Created EFI boot entry
\"Linux Boot Manager
\".");
681 return insert_into_order(slot, first);
684 static int remove_boot_efi(const char *esp_path) {
686 _cleanup_closedir_ DIR *d = NULL;
690 p = strjoina(esp_path, "/EFI
/BOOT
");
696 return log_error_errno(errno, "Failed to open directory
\"%s
\": %m
", p);
699 FOREACH_DIRENT(de, d, break) {
700 _cleanup_close_ int fd = -1;
701 _cleanup_free_ char *v = NULL;
703 if (!endswith_no_case(de->d_name, ".efi
"))
706 if (!startswith_no_case(de->d_name, "boot
"))
709 fd = openat(dirfd(d), de->d_name, O_RDONLY|O_CLOEXEC);
711 return log_error_errno(errno, "Failed to open
\"%s
/%s
\" for reading
: %m
", p, de->d_name);
713 r = get_file_version(fd, &v);
716 if (r > 0 && startswith(v, "systemd
-boot
")) {
717 r = unlinkat(dirfd(d), de->d_name, 0);
719 return log_error_errno(errno, "Failed to remove
\"%s
/%s
\": %m
", p, de->d_name);
721 log_info("Removed
\"%s
/%s
\".", p, de->d_name);
730 static int rmdir_one(const char *prefix, const char *suffix) {
733 p = strjoina(prefix, "/", suffix);
735 if (!IN_SET(errno, ENOENT, ENOTEMPTY))
736 return log_error_errno(errno, "Failed to remove
\"%s
\": %m
", p);
738 log_info("Removed
\"%s
\".", p);
743 static int remove_binaries(const char *esp_path) {
748 p = strjoina(esp_path, "/EFI
/systemd
");
749 r = rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
751 q = remove_boot_efi(esp_path);
755 for (i = ELEMENTSOF(efi_subdirs)-1; i > 0; i--) {
756 q = rmdir_one(esp_path, efi_subdirs[i-1]);
764 static int remove_variables(sd_id128_t uuid, const char *path, bool in_order) {
771 r = find_slot(uuid, path, &slot);
775 r = efi_remove_boot_option(slot);
780 return remove_from_order(slot);
785 static int install_loader_config(const char *esp_path) {
787 char machine_string[SD_ID128_STRING_MAX];
788 _cleanup_(unlink_and_freep) char *t = NULL;
789 _cleanup_fclose_ FILE *f = NULL;
790 sd_id128_t machine_id;
794 r = sd_id128_get_machine(&machine_id);
796 return log_error_errno(r, "Failed to get machine id
: %m
");
798 p = strjoina(esp_path, "/loader
/loader
.conf
");
800 if (access(p, F_OK) >= 0) /* Silently skip creation if the file already exists (early check) */
803 fd = open_tmpfile_linkable(p, O_WRONLY|O_CLOEXEC, &t);
805 return log_error_errno(fd, "Failed to open
\"%s
\" for writing
: %m
", p);
807 f = fdopen(fd, "we
");
813 fprintf(f, "#timeout 3\n");
814 fprintf(f, "#console-mode keep\n");
815 fprintf(f, "default %s-*\n", sd_id128_to_string(machine_id, machine_string));
817 r = fflush_sync_and_check(f);
819 return log_error_errno(r, "Failed to write \"%s\": %m", p);
821 r = link_tmpfile(fd, t, p);
823 return 0; /* Silently skip creation if the file exists now (recheck) */
825 return log_error_errno(r, "Failed to move \"%s\" into place: %m", p);
832 static int help(int argc, char *argv[], void *userdata) {
834 printf("%s [COMMAND] [OPTIONS...]\n"
836 "Install, update or remove the systemd-boot EFI boot manager.\n\n"
837 " -h --help Show this help\n"
838 " --version Print version\n"
839 " --path=PATH Path to the EFI System Partition (ESP)\n"
840 " -p --print-path Print path to the EFI partition\n"
841 " --no-variables Don't touch EFI variables\n"
844 " status Show status of installed systemd-boot and EFI variables\n"
845 " list List boot entries\n"
846 " install Install systemd-boot to the ESP and EFI variables\n"
847 " update Update systemd-boot in the ESP and EFI variables\n"
848 " remove Remove systemd-boot from the ESP and EFI variables\n",
849 program_invocation_short_name);
854 static int parse_argv(int argc, char *argv[]) {
861 static const struct option options[] = {
862 { "help", no_argument, NULL, 'h' },
863 { "version", no_argument, NULL, ARG_VERSION },
864 { "path", required_argument, NULL, ARG_PATH },
865 { "print-path", no_argument, NULL, 'p' },
866 { "no-variables", no_argument, NULL, ARG_NO_VARIABLES },
875 while ((c = getopt_long(argc, argv, "hp", options, NULL)) >= 0)
886 r = free_and_strdup(&arg_path, optarg);
892 arg_print_path = true;
895 case ARG_NO_VARIABLES:
896 arg_touch_variables = false;
903 assert_not_reached("Unknown option");
909 static void read_loader_efi_var(const char *name, char **var) {
912 r = efi_get_variable_string(EFI_VENDOR_LOADER, name, var);
913 if (r < 0 && r != -ENOENT)
914 log_warning_errno(r, "Failed to read EFI variable %s: %m", name);
917 static int verb_status(int argc, char *argv[], void *userdata) {
919 sd_id128_t uuid = SD_ID128_NULL;
922 r = acquire_esp(geteuid() != 0, NULL, NULL, NULL, &uuid);
924 if (arg_print_path) {
925 if (r == -EACCES) /* If we couldn't acquire the ESP path, log about access errors (which is the only
926 * error the
find_esp_and_warn() won
't log on its own) */
927 return log_error_errno(r, "Failed to determine ESP: %m");
935 r = 0; /* If we couldn't determine the path
, then don
't consider that a problem from here on, just show what we
939 _cleanup_free_ char *fw_type = NULL, *fw_info = NULL, *loader = NULL, *loader_path = NULL, *stub = NULL;
940 sd_id128_t loader_part_uuid = SD_ID128_NULL;
942 read_loader_efi_var("LoaderFirmwareType", &fw_type);
943 read_loader_efi_var("LoaderFirmwareInfo", &fw_info);
944 read_loader_efi_var("LoaderInfo", &loader);
945 read_loader_efi_var("StubInfo", &stub);
946 read_loader_efi_var("LoaderImageIdentifier", &loader_path);
949 efi_tilt_backslashes(loader_path);
951 k = efi_loader_get_device_part_uuid(&loader_part_uuid);
952 if (k < 0 && k != -ENOENT)
953 r = log_warning_errno(k, "Failed to read EFI variable LoaderDevicePartUUID: %m");
956 printf(" Firmware: %s (%s)\n", strna(fw_type), strna(fw_info));
958 k = is_efi_secure_boot();
960 r = log_warning_errno(k, "Failed to query secure boot status: %m");
962 printf(" Secure Boot: %sd\n", enable_disable(k));
964 k = is_efi_secure_boot_setup_mode();
966 r = log_warning_errno(k, "Failed to query secure boot mode: %m");
968 printf(" Setup Mode: %s\n", k ? "setup" : "user");
971 printf("Current Loader:\n");
972 printf(" Product: %s\n", strna(loader));
974 printf(" Stub: %s\n", stub);
975 if (!sd_id128_is_null(loader_part_uuid))
976 printf(" ESP: /dev/disk/by-partuuid/%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
977 SD_ID128_FORMAT_VAL(loader_part_uuid));
979 printf(" ESP: n/a\n");
980 printf(" File: %s%s\n", special_glyph(TREE_RIGHT), strna(loader_path));
983 printf("System:\n Not booted with EFI\n\n");
986 k = status_binaries(arg_path, uuid);
992 k = status_variables();
998 k = status_entries(arg_path, uuid);
1006 static int verb_list(int argc, char *argv[], void *userdata) {
1007 _cleanup_(boot_config_free) BootConfig config = {};
1008 sd_id128_t uuid = SD_ID128_NULL;
1012 /* If we lack privileges we invoke find_esp_and_warn() in "unprivileged mode" here, which does two things: turn
1013 * off logging about access errors and turn off potentially privileged device probing. Here we're interested in
1014 * the latter but
not the former
, hence request the mode
, and log about EACCES
. */
1016 r
= acquire_esp(geteuid() != 0, NULL
, NULL
, NULL
, &uuid
);
1017 if (r
== -EACCES
) /* We really need the ESP path for this call, hence also log about access errors */
1018 return log_error_errno(r
, "Failed to determine ESP: %m");
1022 r
= boot_entries_load_config(arg_path
, &config
);
1024 return log_error_errno(r
, "Failed to load bootspec config from \"%s/loader\": %m",
1027 printf("Available boot entries:\n");
1029 for (n
= 0; n
< config
.n_entries
; n
++) {
1030 const BootEntry
*e
= &config
.entries
[n
];
1032 printf(" title: %s%s%s%s%s%s\n",
1034 boot_entry_title(e
),
1036 ansi_highlight_green(),
1037 n
== (unsigned) config
.default_entry
? " (default)" : "",
1040 printf(" version: %s\n", e
->version
);
1042 printf(" machine-id: %s\n", e
->machine_id
);
1043 if (e
->architecture
)
1044 printf(" architecture: %s\n", e
->architecture
);
1046 printf(" linux: %s\n", e
->kernel
);
1047 if (!strv_isempty(e
->initrd
)) {
1048 _cleanup_free_
char *t
;
1050 t
= strv_join(e
->initrd
, " ");
1054 printf(" initrd: %s\n", t
);
1056 if (!strv_isempty(e
->options
)) {
1057 _cleanup_free_
char *t
;
1059 t
= strv_join(e
->options
, " ");
1063 printf(" options: %s\n", t
);
1066 printf(" devicetree: %s\n", e
->device_tree
);
1074 static int verb_install(int argc
, char *argv
[], void *userdata
) {
1076 sd_id128_t uuid
= SD_ID128_NULL
;
1077 uint64_t pstart
= 0, psize
= 0;
1082 r
= acquire_esp(false, &part
, &pstart
, &psize
, &uuid
);
1086 install
= streq(argv
[0], "install");
1088 RUN_WITH_UMASK(0002) {
1089 r
= install_binaries(arg_path
, install
);
1094 r
= install_loader_config(arg_path
);
1100 if (arg_touch_variables
)
1101 r
= install_variables(arg_path
,
1102 part
, pstart
, psize
, uuid
,
1103 "/EFI/systemd/systemd-boot" EFI_MACHINE_TYPE_NAME
".efi",
1109 static int verb_remove(int argc
, char *argv
[], void *userdata
) {
1110 sd_id128_t uuid
= SD_ID128_NULL
;
1113 r
= acquire_esp(false, NULL
, NULL
, NULL
, &uuid
);
1117 r
= remove_binaries(arg_path
);
1119 if (arg_touch_variables
) {
1122 q
= remove_variables(uuid
, "/EFI/systemd/systemd-boot" EFI_MACHINE_TYPE_NAME
".efi", true);
1123 if (q
< 0 && r
== 0)
1130 static int bootctl_main(int argc
, char *argv
[]) {
1132 static const Verb verbs
[] = {
1133 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
1134 { "status", VERB_ANY
, 1, VERB_DEFAULT
, verb_status
},
1135 { "list", VERB_ANY
, 1, 0, verb_list
},
1136 { "install", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_install
},
1137 { "update", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_install
},
1138 { "remove", VERB_ANY
, 1, VERB_MUST_BE_ROOT
, verb_remove
},
1142 return dispatch_verb(argc
, argv
, verbs
, NULL
);
1145 int main(int argc
, char *argv
[]) {
1148 log_parse_environment();
1151 /* If we run in a container, automatically turn of EFI file system access */
1152 if (detect_container() > 0)
1153 arg_touch_variables
= false;
1155 r
= parse_argv(argc
, argv
);
1159 r
= bootctl_main(argc
, argv
);
1163 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;