Booting GPT disk on BIOS systems

This is a simple guide to boot GPT-partitioned disk in systems with BIOS firmware using Syslinux.

Do you need it?

  1. Why do you want to use a GPT-partitioned disk (= GPT disk for short) in systems with BIOS firmware (as opposed to EFI/UEFI firmware, which supports GPT natively)?
    If your disk capacity is larger than 2 terabytes, GPT partition is the only way to access all of them. It doesn't matter whether you connect it through internal bus, through USB, or iSCSI.

  2. Why do you want to use GPT disk as your boot disk? If you only have one disk, that is, or if all of your disks are GPT disks.

Requirements

  1. Your system BIOS must not be fussy about the MBR and partition format in MBR. It should be happy to execute IPL code in MBR as long as the MBR has the correct checksum.
  2. Syslinux (I'm using 4.0.6, earlier versions up to 3.7.6 should work as long as it has the gptmbr.bin file).
  3. Some GPT disk manipulation tools, such as gptfdisk (gdisk, sgdisk) or parted (or gparted).
Note 1: Some BIOSes are fussy. Some of them expect that the bootable partition must be, well, has its "bootable" flag set. While this is fine for MBR disk, this isn't so because GPT specification explicitly forbids it. But this can still be worked on as long as the BIOS isn't fussy about GPT partition too (that is, we simply set that flag in violation of the GPT spec as long as the system boots up).

Note 2: Some BIOSes are even fussier, and perform more checks and refuses to boot from what they think as "invalid" MBR. The thing is, what they consider as "invalid" may in fact be valid MBR partition. If you have this kind of BIOS, then good luck, because you need to manually craft your MBR to make your BIOS believe that it is a valid one.

About bootloaders

Here I will use syslinux because it is the simplest to setup; but it is not the only bootloaders that can do so. Grub2 can definitely do it. Vanilla Grub Legacy (Grub 0.9.7) can't because development stopped long before GPT support was implemented, although there are distro patches (e.g. from Fedora) that make it capable. Grub4Dos - which is a long-running fork of Grub Legacy, doesn't support it yet at the time of writing.

Steps

For the following I will assume that your GPT disk is /dev/sda and your (soon-to-be) bootable partition is partition 3, that is, /dev/sda3. Obviously change all references to /dev/sda, /dev/sda3 and the partition 3 to your own setup.

I will make the assumption that the partition you want to setup is Linux partition (ext2/ext3/ext4).

1. Use GPT partitioning tool to mark that the partition is going to be bootable.
If you use gparted, choose "Manage Flags" and tick "legacy boot".

If you use sgdisk, type

sgdisk -A 3:set:2 /dev/sda
which means set capability bit 2 (=the "legacy BIOS partition") of partition 3 of /dev/sda.

If you use the interactive gdisk tool instead of sgdisk above:

  1. Type gdisk /dev/sda
  2. Enter the Extra functionality (experts only) menu by typing "x"
  3. Choose Set attributes by typing "a"
  4. You will be asked for which partition to update, choose "3"
  5. You will be asked which bit to enable, so choose Legacy BIOS bootable by typing "2".
  6. Save your changes by typing "w".

2. Next, mount the partition somewhere, say in /mnt/data

mount /dev/sda3 /mnt/data

3. Use syslinux to install the boot loader, pretending that it is a regular partition:

extlinux -i /mnt/data
or
extlinux -i /mnt/data/boot
if you want to keep syslinux files under /boot directory.

Then please add the usual syslinux.conf configuration to boot your system - location of your kernel, initrd, rootfs, etc.

4. Copy syslinux IPL which is capable of booting GPT partition to the disk's MBR.
The code is (usually) stored in /usr/share/syslinux/gptmbr.bin. To copy, do this:

dd if=/usr/share/syslinux/gptmbr.bin of=/dev/sda bs=440 count=1

5. You're done!
Do the usual cleanup (un-mount /mnt/data, etc) and then reboot.

6. Additional Note 1
Assuming however, you have done all these correctly and BIOS still won't boot the system (saying no bootable disk found etc), you may need to mark the protective MBR as bootable (see Note1 above).

To this, you need to use "fdisk". Yes, plain old fdisk.

  1. Start fdisk on the disk (fdisk /dev/sda) and ignore the warnings.
  2. Type "a" to toggle the bootable flag, and choose "1" for the partition to enable. We choose partition "1", not "3", because now we are talking about the protective MBR (that fdisk sees); and there is only one partition there - the protective partition.
  3. Save your work by typing "w".

As mentioned above, doing this is actually discouraged, see for example: http://mjg59.dreamwidth.org/8035.html (Matt Garret is the expert on all things UEFI, he is the author of the 'shim' bootloader used by many Linux distros which enables Linux to boot directly on UEFI SecureBoot machines protected by Microsoft keys); but if this is what it takes for your system to boot, then so be it.

7. Warnings

Installing bootloader is not for the faint of heart, and you'd better have a backup plan if this is your *primary* computer, in case you're doing it wrong and the system cannot come to life after that.

Installing a bootloader also means that ALL your previously installed operating system will not boot unless you configure the new bootloader to boot them. If you don't understand the consequences of the actions described in earlier, you'd better stay away from doing this altogether. You have been warned!

The method described above assumes that you use a GPT with a standard protective MBR partition. In this scheme, you only have one partition defined on the MBR - partition of type 'ee' which covers the entire disk; and this is the recommended way to do it.

Some software (including gdisk) actually offers another type of protective MBR called "hybrid MBR", in this case, the GPT partition definitions are copied and mirrored into the MBR partition definitions - if you have 3 partitions in GPT you will have 4 partitions in MBR (3 GPT + original protective).

This is obviously not perfect since the reason why we want to have GPT in the first place is because MBR cannot record the entire disk capacity, in addition, this method is highly discouraged. The reason why is documented here: http://www.rodsbooks.com/gdisk/hybrid.html by the author of gptfdisk, no less.

Originally posted here: Booting GPT disk in BIOS systems using Syslinux.