From 31e57550b552e113bd3d44355b237c41e42beb58 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 6 Aug 2020 21:49:31 +0100 Subject: [PATCH] bootctl: Remove dependency on machine-id. The machine-id is used to create a few directories and setup a default loader entry in loader.conf. Having bootctl create the directories itself is not particularly useful as it does not put anything in them and bootctl install is not guaranteed to be called before an initramfs tool like kernel-install so other programs will always need to have logic to create the directories themselves if they happen to be called before bootctl install is called. On top of this, when using unified kernel images, these are installed to $BOOT/EFI/Linux which removes the need to have the directories created by bootctl at all. This further indicates that these directories should be created by the program that puts something in them rather than by bootctl. Removing the machine-id dependency allows bootctl install to be called even when there's no machine-id in the image. This is useful for image builders such as mkosi which don't have a machine-id when installing systemd-boot (via bootctl) because it should only be generated by systemd when the final image is booted. The default entry in loader.conf based on the machine-id in loader.conf is also removed which shouldn't be a massive loss in usability overall. This commit reverts commit 341890d. --- src/boot/bootctl.c | 47 ++++------------------------------------------ 1 file changed, 4 insertions(+), 43 deletions(-) diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index a663fc5c2d3..11278219dd6 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -888,14 +888,6 @@ static int remove_subdirs(const char *root, const char *const *subdirs) { return r < 0 ? r : q; } -static int remove_machine_id_directory(const char *root, sd_id128_t machine_id) { - char buf[SD_ID128_STRING_MAX]; - - assert(root); - - return rmdir_one(root, sd_id128_to_string(machine_id, buf)); -} - static int remove_binaries(const char *esp_path) { const char *p; int r, q; @@ -978,8 +970,7 @@ static int remove_loader_variables(void) { return r; } -static int install_loader_config(const char *esp_path, sd_id128_t machine_id) { - char machine_string[SD_ID128_STRING_MAX]; +static int install_loader_config(const char *esp_path) { _cleanup_(unlink_and_freep) char *t = NULL; _cleanup_fclose_ FILE *f = NULL; _cleanup_close_ int fd = -1; @@ -999,8 +990,7 @@ static int install_loader_config(const char *esp_path, sd_id128_t machine_id) { return log_oom(); fprintf(f, "#timeout 3\n" - "#console-mode keep\n" - "default %s-*\n", sd_id128_to_string(machine_id, machine_string)); + "#console-mode keep\n"); r = fflush_sync_and_check(f); if (r < 0) @@ -1016,14 +1006,6 @@ static int install_loader_config(const char *esp_path, sd_id128_t machine_id) { return 1; } -static int install_machine_id_directory(const char *root, sd_id128_t machine_id) { - char buf[SD_ID128_STRING_MAX]; - - assert(root); - - return mkdir_one(root, sd_id128_to_string(machine_id, buf)); -} - static int help(int argc, char *argv[], void *userdata) { _cleanup_free_ char *link = NULL; int r; @@ -1531,7 +1513,6 @@ static int verb_install(int argc, char *argv[], void *userdata) { sd_id128_t uuid = SD_ID128_NULL; uint64_t pstart = 0, psize = 0; uint32_t part = 0; - sd_id128_t machine_id; bool install; int r; @@ -1543,10 +1524,6 @@ static int verb_install(int argc, char *argv[], void *userdata) { if (r < 0) return r; - r = sd_id128_get_machine(&machine_id); - if (r < 0) - return log_error_errno(r, "Failed to get machine id: %m"); - install = streq(argv[0], "install"); RUN_WITH_UMASK(0002) { @@ -1568,11 +1545,7 @@ static int verb_install(int argc, char *argv[], void *userdata) { return r; if (install) { - r = install_loader_config(arg_esp_path, machine_id); - if (r < 0) - return r; - - r = install_machine_id_directory(arg_dollar_boot_path(), machine_id); + r = install_loader_config(arg_esp_path); if (r < 0) return r; @@ -1594,7 +1567,7 @@ static int verb_install(int argc, char *argv[], void *userdata) { } static int verb_remove(int argc, char *argv[], void *userdata) { - sd_id128_t uuid = SD_ID128_NULL, machine_id; + sd_id128_t uuid = SD_ID128_NULL; int r, q; r = acquire_esp(false, NULL, NULL, NULL, &uuid); @@ -1605,10 +1578,6 @@ static int verb_remove(int argc, char *argv[], void *userdata) { if (r < 0) return r; - r = sd_id128_get_machine(&machine_id); - if (r < 0) - return log_error_errno(r, "Failed to get machine id: %m"); - r = remove_binaries(arg_esp_path); q = remove_file(arg_esp_path, "/loader/loader.conf"); @@ -1627,19 +1596,11 @@ static int verb_remove(int argc, char *argv[], void *userdata) { if (q < 0 && r >= 0) r = q; - q = remove_machine_id_directory(arg_esp_path, machine_id); - if (q < 0 && r >= 0) - r = 1; - if (arg_xbootldr_path) { /* Remove the latter two also in the XBOOTLDR partition if it exists */ q = remove_subdirs(arg_xbootldr_path, dollar_boot_subdirs); if (q < 0 && r >= 0) r = q; - - q = remove_machine_id_directory(arg_xbootldr_path, machine_id); - if (q < 0 && r >= 0) - r = q; } (void) sync_everything();