From 6526a0446aacda4166be67efda9ac9dc04485613 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Tue, 7 Mar 2017 16:07:39 +0000 Subject: [PATCH] bootman: Automatically determine if the target system is GPT or not The primary difference between our "core" bootloaders and the upcoming GRUB2 support, is that in terms of legacy, syslinux is only used to support a GPT disk. As such our inspection of the root checks if one of the boot-grab methods actually succeeded, and if so, enforce the GPT mask. This is because both of the probe methods are GPT-specific, with the legacy method erroring out in the absence of a proper PTUUID, and our UEFI method checking the XDG bootloader protocol, before using /dev/disk/by-partuuid. This is only supported on GPT. This change unlocks the addition of a simplistic GRUB2 implementation because it will have the LEGACY flags but not the GPT flags, thus the syslinux loader will never be selected, as long as the GRUB loader is placed *first* in the array. Likewise, the GRUB loader will never be able to be loaded for the other configurations because it will never have the GPT flag set. Signed-off-by: Ikey Doherty --- src/bootman/bootman.c | 9 +-------- src/bootman/bootman.h | 2 +- src/bootman/sysconfig.c | 13 +++++++++++-- src/bootman/update.c | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/bootman/bootman.c b/src/bootman/bootman.c index 63c8635..66acd05 100644 --- a/src/bootman/bootman.c +++ b/src/bootman/bootman.c @@ -97,16 +97,9 @@ void boot_manager_free(BootManager *self) static bool boot_manager_select_bootloader(BootManager *self) { - int wanted_boot_mask = 0; const BootLoader *selected = NULL; int selected_boot_mask = 0; - - /* Find legacy */ - if (self->sysconfig->legacy) { - wanted_boot_mask |= BOOTLOADER_CAP_LEGACY; - } else { - wanted_boot_mask |= BOOTLOADER_CAP_UEFI; - } + int wanted_boot_mask = self->sysconfig->wanted_boot_mask; /* Select a bootloader based on the capabilities */ for (size_t i = 0; i < ARRAY_SIZE(bootman_known_loaders); i++) { diff --git a/src/bootman/bootman.h b/src/bootman/bootman.h index c3af33f..586ea8f 100644 --- a/src/bootman/bootman.h +++ b/src/bootman/bootman.h @@ -84,7 +84,7 @@ typedef struct SystemConfig { char *prefix; /**prefix = realp; + c->wanted_boot_mask = 0; - /* Find legacy relative to root */ + /* Find legacy relative to root, on GPT */ boot = get_legacy_boot_device(realp); if (boot) { c->boot_device = boot; - c->legacy = true; + c->wanted_boot_mask |= BOOTLOADER_CAP_LEGACY; LOG_INFO("Discovered legacy boot device: %s", boot); } else { + /* Discover UEFI boot */ c->boot_device = get_boot_device(); + c->wanted_boot_mask |= BOOTLOADER_CAP_UEFI; } + /* Our probe methods are GPT only. If we found one, it's definitely GPT */ if (c->boot_device) { rel = realpath(c->boot_device, NULL); if (!rel) { @@ -78,7 +82,12 @@ SystemConfig *cbm_inspect_root(const char *path) c->boot_device = rel; LOG_INFO("Discovered boot device: %s", rel); } + c->wanted_boot_mask |= BOOTLOADER_CAP_GPT; + } else { + /* Legacy boot, non-GPT */ + c->wanted_boot_mask = BOOTLOADER_CAP_LEGACY; } + c->root_device = cbm_probe_path(realp); return c; diff --git a/src/bootman/update.c b/src/bootman/update.c index 5eeb0c3..0a28326 100644 --- a/src/bootman/update.c +++ b/src/bootman/update.c @@ -59,7 +59,7 @@ bool boot_manager_update(BootManager *self) /* TODO: decide how legacy device detection works */ /* For now legacy means /boot is on the / partition */ - if (self->sysconfig->legacy) { + if ((self->sysconfig->wanted_boot_mask & BOOTLOADER_CAP_LEGACY) == BOOTLOADER_CAP_LEGACY) { LOG_DEBUG("Skipping to legacy-native-install (no mount)"); goto perform; }