diff --git a/src/bootman/sysconfig.c b/src/bootman/sysconfig.c index 7f3d6a6..ecb0f3b 100644 --- a/src/bootman/sysconfig.c +++ b/src/bootman/sysconfig.c @@ -77,9 +77,10 @@ SystemConfig *cbm_inspect_root(const char *path, bool image_mode) * UEFI. This is due to GPT being able to contain a legacy boot device * *and* an ESP at the same time. Native UEFI takes precedence. */ - if (!native_uefi) { + if (!native_uefi || image_mode) { boot = get_legacy_boot_device(realp); } + if (boot) { c->boot_device = boot; c->wanted_boot_mask = BOOTLOADER_CAP_LEGACY | BOOTLOADER_CAP_GPT; @@ -88,7 +89,9 @@ SystemConfig *cbm_inspect_root(const char *path, bool image_mode) } /* Now try to find the system ESP */ - boot = get_boot_device(); + if (!image_mode) { + boot = get_boot_device(); + } if (boot) { c->boot_device = boot; c->wanted_boot_mask = BOOTLOADER_CAP_UEFI | BOOTLOADER_CAP_GPT; diff --git a/src/bootman/update.c b/src/bootman/update.c index 0a28326..0fb0ff3 100644 --- a/src/bootman/update.c +++ b/src/bootman/update.c @@ -184,6 +184,14 @@ static bool boot_manager_update_image(BootManager *self) return false; } + /* Reinit bootloader for image mode to ensure the bootloader is then + * re-initialised for the current settings and environment. + */ + if (!boot_manager_set_boot_dir(self, boot_dir)) { + LOG_FATAL("Cannot re-initialise bootloader for image mode"); + return false; + } + /* Sort them to find the newest kernel */ nc_array_qsort(kernels, kernel_compare_reverse); diff --git a/src/cli/ops/update.c b/src/cli/ops/update.c index 2061b2c..edc4fe2 100644 --- a/src/cli/ops/update.c +++ b/src/cli/ops/update.c @@ -24,7 +24,6 @@ bool cbm_command_update(int argc, char **argv) { autofree(char) *root = NULL; autofree(BootManager) *manager = NULL; - bool image_mode = false; bool forced_image = false; if (!cli_default_args_init(&argc, &argv, &root, &forced_image)) { @@ -47,7 +46,9 @@ bool cbm_command_update(int argc, char **argv) } /* Anything not / is image mode */ if (!streq(realp, "/")) { - image_mode = true; + boot_manager_set_image_mode(manager, true); + } else { + boot_manager_set_image_mode(manager, forced_image); } /* CBM will check this again, we just needed to check for @@ -56,19 +57,13 @@ bool cbm_command_update(int argc, char **argv) return false; } } else { + boot_manager_set_image_mode(manager, forced_image); /* Default to "/", bail if it doesn't work. */ if (!boot_manager_set_prefix(manager, "/")) { return false; } } - if (forced_image) { - boot_manager_set_image_mode(manager, true); - } else { - /* Set the image mode */ - boot_manager_set_image_mode(manager, image_mode); - } - /* Let CBM take care of the rest */ return boot_manager_update(manager); }