Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootman: only do partitionless boot when the bootloader supports it #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/bootloaders/bootloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ typedef int (*boot_loader_caps)(const BootManager *);

typedef enum {
BOOTLOADER_CAP_MIN = 1 << 0,
BOOTLOADER_CAP_UEFI = 1 << 1, /**<Bootloader supports UEFI */
BOOTLOADER_CAP_GPT = 1 << 2, /**<Bootloader supports GPT boot partition */
BOOTLOADER_CAP_LEGACY = 1 << 3, /**<Bootloader supports legacy boot */
BOOTLOADER_CAP_EXTFS = 1 << 4, /**<Bootloader supports ext2/3/4 */
BOOTLOADER_CAP_FATFS = 1 << 5, /**<Bootloader supports vfat */
BOOTLOADER_CAP_MAX = 1 << 6
BOOTLOADER_CAP_UEFI = 1 << 1, /**<Bootloader supports UEFI */
BOOTLOADER_CAP_GPT = 1 << 2, /**<Bootloader supports GPT boot partition */
BOOTLOADER_CAP_LEGACY = 1 << 3, /**<Bootloader supports legacy boot */
BOOTLOADER_CAP_EXTFS = 1 << 4, /**<Bootloader supports ext2/3/4 */
BOOTLOADER_CAP_FATFS = 1 << 5, /**<Bootloader supports vfat */
BOOTLOADER_CAP_PARTLESS = 1<< 6, /**<Bootloader supports partitionless boot */
BOOTLOADER_CAP_MAX = 1 << 7
} BootLoaderCapability;

/**
Expand Down
3 changes: 2 additions & 1 deletion src/bootloaders/extlinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ static int extlinux_get_capabilities(const BootManager *manager)
return 0;
}

return BOOTLOADER_CAP_GPT | BOOTLOADER_CAP_LEGACY | BOOTLOADER_CAP_EXTFS;
return BOOTLOADER_CAP_GPT | BOOTLOADER_CAP_LEGACY | BOOTLOADER_CAP_EXTFS |
BOOTLOADER_CAP_PARTLESS;
}

__cbm_export__ const BootLoader extlinux_bootloader = {.name = "extlinux",
Expand Down
2 changes: 1 addition & 1 deletion src/bootloaders/grub2.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ int grub2_get_capabilities(const BootManager *manager)
return 0;
}
/* Or in other words, we're the last bootloader candidate. */
return BOOTLOADER_CAP_LEGACY | BOOTLOADER_CAP_EXTFS;
return BOOTLOADER_CAP_LEGACY | BOOTLOADER_CAP_EXTFS | BOOTLOADER_CAP_PARTLESS;
}

__cbm_export__ const BootLoader grub2_bootloader = {.name = "grub2",
Expand Down
3 changes: 2 additions & 1 deletion src/bootloaders/syslinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ static int syslinux_get_capabilities(const BootManager *manager)
return 0;
}

return BOOTLOADER_CAP_GPT | BOOTLOADER_CAP_LEGACY | BOOTLOADER_CAP_FATFS;
return BOOTLOADER_CAP_GPT | BOOTLOADER_CAP_LEGACY | BOOTLOADER_CAP_FATFS |
BOOTLOADER_CAP_PARTLESS;
}

__cbm_export__ const BootLoader syslinux_bootloader = {.name = "syslinux",
Expand Down
13 changes: 10 additions & 3 deletions src/bootman/bootman.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,9 @@ int mount_boot(BootManager *self, char **boot_directory)

/*
* Already mounted at the default boot dir or boot doesn't have its own partition,
* we check if /boot is empty, if it's not then we assume it's a "partitionless" /boot
* (the system has no /boot partition), in both cases there's nothing for us to do
* in both cases there's nothing for us to do.
*/
if (cbm_system_is_mounted(boot_dir) || !cbm_is_dir_empty(boot_dir)) {
if (cbm_system_is_mounted(boot_dir) || check_partitionless_boot(self, boot_dir)) {
LOG_INFO("boot_dir is already mounted: %s", boot_dir);
*boot_directory = strdup(boot_dir);
if (*boot_directory) {
Expand Down Expand Up @@ -1011,6 +1010,14 @@ bool boot_manager_is_update_efi_vars(BootManager *self)
return self->update_efi_vars;
}

bool check_partitionless_boot(const BootManager *self, const char *boot_dir)
{
assert(self != NULL);
return ((self->bootloader->get_capabilities(self) & BOOTLOADER_CAP_PARTLESS)
&& !(self->sysconfig->wanted_boot_mask & BOOTLOADER_CAP_UEFI)
&& !cbm_is_dir_empty(boot_dir));
}

/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
Expand Down
9 changes: 9 additions & 0 deletions src/bootman/bootman_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ int kernel_compare_reverse(const void *a, const void *b);
*/
const char *cbm_get_fstype_name(const char *boot_device);

/**
* Check if the system supports a "partitionless" (the system has no /boot partition) boot.
* Conditions are:
* - The bootloader supports this.
* - The system is not UEFI.
* - The /boot folder is not empty.
*/
bool check_partitionless_boot(const BootManager *self, const char *boot_dir);

/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
Expand Down