[haiku-bugs] Re: [Haiku] #4028: Hybrid GPT/MBR Initial Program Loader

  • From: "meianoite" <trac@xxxxxxxxxxxx>
  • Date: Thu, 02 Jun 2011 17:40:01 -0000

#4028: Hybrid GPT/MBR Initial Program Loader
----------------------------+---------------------------
   Reporter:  meianoite     |      Owner:  axeld
       Type:  enhancement   |     Status:  new
   Priority:  normal        |  Milestone:  R1
  Component:  File Systems  |    Version:  R1/pre-alpha1
 Resolution:                |   Keywords:
 Blocked By:                |   Blocking:
Has a Patch:  1             |   Platform:  All
----------------------------+---------------------------
Description changed by meianoite:

Old description:

> 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.

New description:

 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.

--

-- 
Ticket URL: <http://dev.haiku-os.org/ticket/4028#comment:5>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: