Opened 15 years ago

Last modified 9 years ago

#4028 closed enhancement

Hybrid GPT/MBR Initial Program Loader — at Version 5

Reported by: meianoite Owned by: axeld
Priority: normal Milestone: R1
Component: File Systems Version: R1/pre-alpha1
Keywords: GPT, EFI, MBR Cc: planche2k@…, phoudoin
Blocked By: Blocking:
Platform: All

Description (last modified by meianoite)

Attached is a 432 bytes MBR IPL (Initial Program Loader) that looks for the UUID of a Haiku Boot GUID partition and boots it, falling back to MBR partitions if said UUID isn't found or if the (primary) GPT is corrupted or non-existent.

Its usefulness is in being a versatile, "universal" IPL that supports both partitioning styles, allowing it to be used transparently and even facilitating the conversion between partitioning styles, should the need for more partitions or volumes over 2TiB arise (for instance when cloning an older disk to a newer, more capacious one).

It also paves the way for Haiku to create and support booting from multiple volumes larger than 2TiB, which we're in the very privileged position of enjoying efficiently in the near future due to BFS. Another use case is taking a disk from a Intel EFI machine, plugging it on a BIOS machine and boot just fine; and vice-versa.

As mentioned, if there are valid partitions defined in the MBR, and the primary GPT becomes corrupt, it can fall back to loading the MBR partition with the active flag set, if one is defined.

Currently there's no provision for falling back to the GPT copy that lives in the end of the disk, due to the 512 bytes constraint; supporting this is unlikely given that the code is packed tight. An alternative would be disabling support for booting from MBR using BIOS calls other than Int13h function 42h, "Extended Read From Disk" (i.e., LBA mode). It's unlikely that any machine that Haiku supports won't have this BIOS function, but having an "universal" IPL should be quite useful to, say, people using Haiku to rewrite a corrupt MBR on another disk using the excellent DiskProbe.

The number of sectors loaded depends on the boot style. Booting from a MBR partition assumes that the Partition Boot Record is one sector long, whereas booting from a GPT partition assumes a partition exclusive for a system loader and will either copy its entirety into memory starting from address 0x7c00, or will copy up to circa 545KiB, whichever is smaller. Thus, it remains compatible with the FreeBSD gptloader and should work for loading Bootman from an exclusive Haiku boot manager partition as well.

It should be easy to adjust the UUID signature as needed. It lives at offset 0x1a0 (416), leaving plenty of space before the 32-bit disk signature at offset 0x1b8 (440), so compatibility with Microsoft Windows and other OSs is maintained.

Change History (6)

comment:1 by meianoite, 15 years ago

Description: modified (diff)

comment:2 by andreasf, 15 years ago

Cc: planche2k@… added

comment:3 by meianoite, 15 years ago

Description: modified (diff)

by meianoite, 14 years ago

Attachment: haiku_gpt_mbr.S added

Updated with fixed comments and nicer formatting (set your editor to 4 spaces per tab)

comment:4 by mmadia, 14 years ago

patch: 01

comment:5 by meianoite, 13 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.