Opened 15 years ago

Last modified 9 years ago

#4028 closed enhancement

Hybrid GPT/MBR Initial Program Loader — at Version 3

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 512 byte PMBR boot loader that looks for the UUID of a Haiku GPT 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 generalised IPL that supports both partitioning styles, allowing it to be used transparently and even allowing disks to be converted from one partitioning style to the other with ease, 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 would require either some major refactoring of the code or disabling the support for booting from MBR using calls to int13h other than function 4200h, "LBA Read from Disk".

It was tested on emulators and on my actual, proper computer. Loading Windows, Haiku and FreeBSD was tested (UUID must be changed accordingly, of course); for the GPT boot, the number of sectors to load from the partition is adjustable (needed by FreeBSD's "gptloader" on a freebsd-boot UUID partition), probably needed by Haiku as well since stage1 is 2 sectors big), but beware that int13h 4200h only supports up to 127 (0x7f) sectors, or a loader of almost 64KiB; so don't specify a larger number. This is not checked on the code, again because of space constraints.

Change History (4)

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, 15 years ago

Attachment: haiku_gpt_mbr.S added

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

Note: See TracTickets for help on using tickets.