Skip to contentSkip to conversation

wic: Add gpt-hybrid partition layout

PATCH New Joshua Watt 1 participant 1 message Aug 30, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wic: Add gpt-hybrid partition layout

Add support for formatting a disk with a hybrid MBR & GPT partition scheme. In this scheme, the primary partitioning method is GPT, but a valid MBR header is also written than can point to a subset of the GPT partitions on the disk (any partitions marked with the --mbr flag will be included in this MBR). The primary purpose of this method is to allow for SoCs that can only find a bootloader in an MBR partition to use GPT once the bootloader is running. As an example, older versions of the Raspberry Pi firmware can only parse MBR partitions to find a kernel (or other bootloader like u-boot), but once those have booted GPT partitions can be used.

In addition to the partitions annotated with the --mbr, a "protective" GPT partition of type 0xEE is added, as the existence of such a partition is the indication to tooling that this a hybrid MBR and that the GPT partition table should be parsed instead.

---
 scripts/lib/wic/ksparser.py              |  3 +-
 scripts/lib/wic/partition.py             |  1 +
 scripts/lib/wic/plugins/imager/direct.py | 82 +++++++++++++++++++-----
 3 files changed, 69 insertions(+), 17 deletions(-)
scripts/lib/wic/ksparser.py +2 -1
index 667b2ff9c33..7ef3dc83ddc 100644
@@ -188,11 +188,12 @@ class KickStart():
         part.add_argument('--uuid')
         part.add_argument('--fsuuid')
         part.add_argument('--no-fstab-update', action='store_true')
+        part.add_argument('--mbr', action='store_true')
 
         bootloader = subparsers.add_parser('bootloader')
         bootloader.add_argument('--append')
         bootloader.add_argument('--configfile')
-        bootloader.add_argument('--ptable', choices=('msdos', 'gpt'),
+        bootloader.add_argument('--ptable', choices=('msdos', 'gpt', 'gpt-hybrid'),
                                 default='msdos')
         bootloader.add_argument('--timeout', type=int)
         bootloader.add_argument('--source')
scripts/lib/wic/partition.py +1 -0
index f11c393df51..b1a2306dd12 100644
@@ -60,6 +60,7 @@ class Partition():
         self.has_fstab = False
         self.update_fstab_in_rootfs = False
         self.hidden = args.hidden
+        self.mbr = args.mbr
 
         self.lineno = lineno
         self.source_file = ""
scripts/lib/wic/plugins/imager/direct.py +66 -16

147 lines not on this page · raw message

Signature · 1 line
2.34.1