blsuki: Add support for the XBOOTLDR partition
cover blsuki: Add support for the XBOOTLDR partition
The default ESP partition on some systems is limited in space and storing a number of kernel and initrd images can fill it up quickly.
It's not always practical to increase the size of the existing ESP, so the Boot Loader Spec defines a new Extended Boot Loader Partition (XBOOTLDR) with GPT type GUID of bc13c2ff-59e6-4262-a352-b275fd6f7172 to be searched for BLS enties and UKIs in addition to the ESP.
Currently searching for this partition is based on the $root variable, but the spec requires for this partition to be on the same device as the ESP. In many cases that would be the case for $root, but there may be exceptions. After looking into it a bit I'm thinking it may be better in this case to select the device to search based on $cmdpath instead Please let me know your oppinion on this.
More datails can be found at https://uapi-group.org/specifications/specs/boot_loader_specification/
Radoslav Kolev (2):
blsuki: scan XBOOTLDR partition for BLS/UKIs if it exists
blsuki: search default location on XBOOTLDR partition, even if entries
found on ESP
grub-core/commands/blsuki.c | 95 ++++++++++++++++++++++++++++++++---- include/grub/gpt_partition.h | 7 +++ 2 files changed, 93 insertions(+), 9 deletions(-)
Signature · 7 lines
2.51.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 1/2 blsuki: scan XBOOTLDR partition for BLS/UKIs if it exists
The default ESP partition on some systems is limited in space and storing a number of kernel and initrd images can fill it up quickly.
It's not always practical to increase the size of the existing ESP, so the Boot Loader Spec defines a new Extended Boot Loader Partition (XBOOTLDR) with GPT type GUID of bc13c2ff-59e6-4262-a352-b275fd6f7172 to be searched for BLS enties and UKIs in addition to the ESP.
see https://uapi-group.org/specifications/specs/boot_loader_specification/
--- grub-core/commands/blsuki.c | 86 +++++++++++++++++++++++++++++++++--- include/grub/gpt_partition.h | 7 +++ 2 files changed, 86 insertions(+), 7 deletions(-)
grub-core/commands/blsuki.c +79 -7
@@ -31,6 +31,7 @@#include <grub/safemath.h> #include <grub/lib/envblk.h> #include <filevercmp.h> +#include <grub/gpt_partition.h> #ifdef GRUB_MACHINE_EFI #include <grub/efi/efi.h>
@@ -1245,6 +1246,33 @@ blsuki_find_entry (struct find_entry_info *info, bool enable_fallback, enum blsureturn GRUB_ERR_NONE ; } +static const grub_guid_t xbootldr_type =GRUB_GPT_PARTITION_TYPE_XBOOTLDR ; +static int find_xbootldr_iter (grub_disk_t disk,const grub_partition_t p,void *data) { +char **xbootldr_part = data; +struct grub_gpt_partentry gptdata; +grub_partition_t p2; + +grub_dprintf ("blsuki" ,"Checking part number %d index %d \n" , p->number, p->index); + + p2 = disk->partition; + disk->partition = p->parent; +if (grub_disk_read (disk, p->offset, p->index,sizeof (gptdata), &gptdata)) + { + disk->partition = p2; +return 0 ; + } + disk->partition = p2; +grub_dprintf ("blsuki" ,"Gptdata.type: %x %x %x %x\n" , gptdata.type.data1, gptdata.type.data2, gptdata.type.data3, gptdata.type.data4[0 ]); +grub_dprintf ("blsuki" ,"XBOOTLDR.type: %x %x %x %x\n" , xbootldr_type.data1, xbootldr_type.data2, xbootldr_type.data3, xbootldr_type.data4[0 ]); +if (!grub_memcmp (&gptdata.type, &xbootldr_type,16 )) + { + *xbootldr_part =grub_xasprintf ("%s,%s" , disk->name,grub_partition_get_name (p)); +grub_dprintf ("blsuki" ,"XBOOTLDR found! setting name to %s\n" , *xbootldr_part); +return 1 ; + } +return 0 ; +} +static grub_err_t blsuki_load_entries (char *path,bool enable_fallback,enum blsuki_cmd_type cmd_type) {
@@ -1257,6 +1285,7 @@ blsuki_load_entries (char *path, bool enable_fallback, enum blsuki_cmd_type cmd_const char *cmd_dir =NULL ;grub_size_t dir_size;const char *ext =NULL ; +char *xbootldr_part =NULL ;struct find_entry_info info = { .dev =NULL , .fs =NULL ,
@@ -1329,16 +1358,59 @@ blsuki_load_entries (char *path, bool enable_fallback, enum blsuki_cmd_type cmd_ tmp =grub_stpcpy (tmp, cmd_dir); dir = default_dir; } +//will search ESP ($root) if no device specified + r =blsuki_set_find_entry_info (&info, dir, devid, cmd_type); +if (r ==GRUB_ERR_NONE ) + r =blsuki_find_entry (&info, enable_fallback, cmd_type); +if (r !=GRUB_ERR_NONE ) + goto finish; +/* +* No device and partition specified - default behaviour as +* per the spec is to search both ESP and XBOOTLDR partitions +*/ +if (devid ==NULL ) + { +//find XBOOTLDR partition if it exists and scan it for entries +grub_disk_t esp_disk =grub_disk_open (grub_env_get ("root" )); +grub_err_t err; - r =blsuki_set_find_entry_info (&info, dir, devid, cmd_type); -if (r ==GRUB_ERR_NONE ) - r =blsuki_find_entry (&info, enable_fallback, cmd_type); +if (esp_disk) + { +grub_free (esp_disk->partition); +//we want to access the disk device containing the ESP, so set partition to NULL + esp_disk->partition =NULL ; + err =grub_gpt_partition_map_iterate (esp_disk, find_xbootldr_iter, &xbootldr_part); +if (err) + { +grub_dprintf ("blsuki" ,"iterating partitions failed with err: %d\n" ,err); + goto finish; + } + +if (xbootldr_part) + { +grub_dprintf ("blsuki" ,"Found XBOOTLDR partition %s\n" , xbootldr_part); + r =blsuki_set_find_entry_info (&info, dir, xbootldr_part, cmd_type); +if (r ==GRUB_ERR_NONE ) + r =blsuki_find_entry (&info, enable_fallback, cmd_type); +if (r !=GRUB_ERR_NONE ) + goto finish; + } +else + { +grub_dprintf ("blsuki" ,"XBOOTLDR partition not found (%s)!\n" , xbootldr_part); + } +grub_disk_close (esp_disk); + } +else grub_dprintf ("blsuki" ,"Failed to open ESP disk looking for XBOOTLDR partition\n" ); + } + finish: +if (info.dev !=NULL ) +grub_device_close (info.dev); -if (info.dev !=NULL ) -grub_device_close (info.dev); +grub_free (default_dir); +grub_free (xbootldr_part); -grub_free (default_dir); -return r; +return r; } static bool
include/grub/gpt_partition.h +7 -0
@@ -41,6 +41,13 @@ { 0x85, 0xD2, 0xE1, 0xE9, 0x04, 0x34, 0xCF, 0xB3 } \ } +#define GRUB_GPT_PARTITION_TYPE_XBOOTLDR \ + { grub_cpu_to_le32_compile_time (0xbc13c2ffU),\ + grub_cpu_to_le16_compile_time (0x59e6), \ + grub_cpu_to_le16_compile_time (0x4262), \ + { 0xa3, 0x52, 0xb2, 0x75, 0xfd, 0x6f, 0x71, 0x72 } \ + } +struct grub_gpt_header {grub_uint8_t magic[8 ];
Signature · 7 lines
2.51.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 2/2 blsuki: search default location on XBOOTLDR partition, even if entries found on ESP
In reply to Radoslav Kolev via Grub-devel--- grub-core/commands/blsuki.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
grub-core/commands/blsuki.c +7 -2
@@ -106,6 +106,7 @@ struct read_entry_infoconst char *dirname;enum blsuki_cmd_type cmd_type;grub_file_t file; +bool entry_found; };struct find_entry_info
@@ -635,7 +636,10 @@ blsuki_read_entry (const char *filename,#endif if (err ==GRUB_ERR_NONE ) -blsuki_add_entry (entry); + { +blsuki_add_entry (entry); + info->entry_found = true; + }else grub_free (entry);
@@ -1200,6 +1204,7 @@ blsuki_find_entry (struct find_entry_info *info, bool enable_fallback, enum blsu dir_fs = info->fs; read_entry_info.devid = info->devid; read_entry_info.cmd_type = cmd_type; + read_entry_info.entry_found = false; r = dir_fs->fs_dir (dir_dev, read_entry_info.dirname, blsuki_read_entry, &read_entry_info);
@@ -1215,7 +1220,7 @@ blsuki_find_entry (struct find_entry_info *info, bool enable_fallback, enum blsu* can find the files there. If we can't find UKI entries, fallback to * "/EFI/Linux" on the EFI system partition. */ -if (entries ==NULL && fallback == false && enable_fallback == true) +if ( read_entry_info.entry_found == false && fallback == false && enable_fallback == true) {if (cmd_type ==BLSUKI_BLS_CMD ) cmd_dir =GRUB_BLS_CONFIG_PATH ;
Signature · 7 lines
2.51.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 25 lines · Radoslav Kolev via Grub-devel
The default ESP partition on some systems is limited in space and storing a number of kernel and initrd images can fill it up quickly.
It's not always practical to increase the size of the existing ESP, so the Boot Loader Spec defines a new Extended Boot Loader Partition (XBOOTLDR) with GPT type GUID of bc13c2ff-59e6-4262-a352-b275fd6f7172 to be searched for BLS enties and UKIs in addition to the ESP.
Currently searching for this partition is based on the $root variable, but the spec requires for this partition to be on the same device as the ESP. In many cases that would be the case for $root, but there may be exceptions. After looking into it a bit I'm thinking it may be better in this case to select the device to search based on $cmdpath instead Please let me know your oppinion on this.
More datails can be found at https://uapi-group.org/specifications/specs/boot_loader_specification/
Radoslav Kolev (2):
blsuki: scan XBOOTLDR partition for BLS/UKIs if it exists
blsuki: search default location on XBOOTLDR partition, even if entries
found on ESP
Quoted 7 lines
grub-core/commands/blsuki.c | 95 ++++++++++++++++++++++++++++++++---- include/grub/gpt_partition.h | 7 +++ 2 files changed, 93 insertions(+), 9 deletions(-)--
2.51.1
Would it be worth it to consider also searching the ROOT volume too (in /boot/loader/entries) similarly to XBOOTLDR, especially in the case where /boot is part of the main disk volume? This case exists in Fedora Cloud (F44+ as a Btrfs subvolume[1]), RHEL (RHEL10+ as a folder in the root XFS volume[2]), and SUSE distributions (where /boot is a folder in the root subvolume and contents of it are subvolumes[3]).
It's now common enough that basic autodiscovery of those cases makes sense to be able to consider.
[1]: https://fedoraproject.org/wiki/Changes/BtrfsBootForCloud
[2]: https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/10.0_release_notes/new-features-and-enhancements#Jira-RHELDOCS-18902
[3]: https://rootco.de/2018-01-19-opensuse-btrfs-subvolumes/
Signature · 6 lines
真実はいつも一つ!/ Always, there's only one truth! _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 32 lines · Neal Gompa
Quoted 29 lines · Radoslav Kolev via Grub-devel
The default ESP partition on some systems is limited in space and storing a number of kernel and initrd images can fill it up quickly.
It's not always practical to increase the size of the existing ESP, so the Boot Loader Spec defines a new Extended Boot Loader Partition (XBOOTLDR) with GPT type GUID of bc13c2ff-59e6-4262-a352-b275fd6f7172 to be searched for BLS enties and UKIs in addition to the ESP.
Currently searching for this partition is based on the $root variable, but the spec requires for this partition to be on the same device as the ESP. In many cases that would be the case for $root, but there may be exceptions. After looking into it a bit I'm thinking it may be better in this case to select the device to search based on $cmdpath instead Please let me know your oppinion on this.
More datails can be found at https://uapi-group.org/specifications/specs/boot_loader_specification/
Radoslav Kolev (2):
blsuki: scan XBOOTLDR partition for BLS/UKIs if it exists
blsuki: search default location on XBOOTLDR partition, even if entries
found on ESPgrub-core/commands/blsuki.c | 95 ++++++++++++++++++++++++++++++++---- include/grub/gpt_partition.h | 7 +++ 2 files changed, 93 insertions(+), 9 deletions(-)
Quoted 7 lines
Quoted 3 lines
--
2.51.1Would it be worth it to consider also searching the ROOT volume too (in
/boot/loader/entries) similarly to XBOOTLDR, especially in the case where /boot is part of the main disk volume?
No, as that is very explicitly against the specification, so it does not belong in the blsuki module.
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 9 lines · Neal Gompa
Would it be worth it to consider also searching the ROOT volume too (in
/boot/loader/entries) similarly to XBOOTLDR, especially in the case where /boot is part of the main disk volume? This case exists in Fedora Cloud (F44+ as a Btrfs subvolume[1]), RHEL (RHEL10+ as a folder in the root XFS volume[2]), and SUSE distributions (where /boot is a folder in the root subvolume and contents of it are subvolumes[3]).It's now common enough that basic autodiscovery of those cases makes sense to be able to consider.
My logic has been to keep as close to the spec as possible if the blscfg command is
called with no parameters. Scenarios like the above can be handled using the --path
parameter.
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 11 lines · Radoslav Kolev
The default ESP partition on some systems is limited in space and storing a number of kernel and initrd images can fill it up quickly.
It's not always practical to increase the size of the existing ESP, so the Boot Loader Spec defines a new Extended Boot Loader Partition (XBOOTLDR) with GPT type GUID of bc13c2ff-59e6-4262-a352-b275fd6f7172 to be searched for BLS enties and UKIs in addition to the ESP.
Quoted 6 lines
Currently searching for this partition is based on the $root variable, but the spec requires for this partition to be on the same device as the ESP. In many cases that would be the case for $root, but there may be exceptions. After looking into it a bit I'm thinking it may be better in this case to select the device to search based on $cmdpath instead Please let me know your oppinion on this.
Yes it is extremely important to ensure the autodiscovered partition is on the same device as the ESP where the running bootloader was loaded from. Otherwise bad things can happen - for example, someone can plug in a usb disk and trick you into booting something that you never intended to. It's fundamental for autodiscovery not only in EFI mode, but in userspace later, so please ensure this restriction is respected. Thanks
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 7 lines · Luca Boccassi
Yes it is extremely important to ensure the autodiscovered partition is on the same device as the ESP where the running bootloader was loaded from. Otherwise bad things can happen - for example, someone can plug in a usb disk and trick you into booting something that you never intended to. It's fundamental for autodiscovery not only in EFI mode, but in userspace later, so please ensure this restriction is respected.
I would say in UEFI case the best approach is getting the device name via grub_efi_get_loaded_image()->device_handle. I'm just not sure if the XBOOTLDR partition can be used in non-UEFI systems that support BLS (like s390?) and what would be a way to handle those cases as well.
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel