Is a hybrid Linux USB-Stick for UEFI & legacy BIOS possible?

It's possible, and it's very frequently done with both external USB sticks and internal drives.

Regarding partition table types:

  • BIOS normally doesn't need any partition table. It is only interested in the bootstrap code part that is the first 440 bytes of your MBR. (Although there are exceptions. Some BIOS implementations actually do break if they cannot find a MBR with one of the usual partition types. Hopefully those are rare.)

    The GPT partition table doesn't physically replace a MBR – it always starts at sector 1, while the MBR is in sector 0 – so it's possible for a disk to have both. In fact, most GPT disks do have a "protective MBR" containing just a single partition that covers the entire disk, to prevent older MBR-only partitioning tools from accidentally destroying the data.

    So you can install, for example, the Syslinux boot sector into your MBR, and it will boot. (The syslinux-install_update script will do this for you, but you can look for gptmbr.bin in your syslinux package to do it manually.)

    Much like the "active" flag on MBR partitions, Syslinux will look for the "legacy BIOS bootable" flag on GPT partitions (bit 2 – UEFI spec 2.4 section 5.3.3 table 20); the aforementioned script also sets that flag automatically if you have sgdisk (from gptfdisk) installed.

    GRUB can also be used, but it's also a bit more annoying. Since GRUB 2 wants to "embed" parts of itself in the traditionally-unused sectors 1-62, it would overwrite a GPT that's stored in the same location. So you might need to create a dedicated partition of 2-4 MB and mark it as BIOS-bootable, so that grub-install would find itself an embedding place.

  • On the other hand, the UEFI specification does require support for MBR partition types (section 12.3.1) and assign the MBR partition type 0xEF to the EFI system partition (section 5.2.2).

    So if you for some reason cannot get your disk working with GPT, you still can create an EFI system partition on MBR, and it will be used as long as it has the correct filesystem and all the necessary files (section 12.3.1.3):

    For removable media devices there must be only one UEFI-compliant system partition, and that partition must contain an UEFI-defined directory in the root directory. The directory will be named EFI. All OS loaders and applications will be stored in a subdirectory below EFI called BOOT. There must only be one executable EFI image for each supported processor architecture in the BOOT directory. For removable media to be bootable under EFI, it must be built in accordance with the rules laid out in Section 3.4.1.1.

Regarding operating systems, Linux generally does not care the slightest bit about whether it's booted from BIOS today and from UEFI tomorrow. I've had to reboot my laptop from UEFI mode to "BIOS compatibility" mode and back maybe a hundred times this week, while trying to find a bug in the 3.17 UEFI support...


Note that the "BIOS to UEFI Transformation" article is about a quite different thing. It describes how to install UEFI itself – an UEFI implementation called "DUET" – to be started from a BIOS-only system. It has nothing to do with booting an operating system directly from BIOS.


Yes, this is possible.

The basic idea is to GPT partition your USB stick like this:

  1. BIOS boot partition (GPT type 1686148-6449-6E6F-744E-656564454649) - 1 MiB, no filesystem
  2. EFI system partition (GPT type C12A7328-F81F-11D2-BA4B-00A0C93EC93B) - 200 MiB, VFAT filesystem
  3. Linux boot partition (GPT type 0FC63DAF-8483-4772-8E79-3D69D8477DE4) - 1 GiB, ext4 filesystem
  4. Linux root/home file system (GPT type 0FC63DAF-8483-4772-8E79-3D69D8477DE4) - remaining space, XFS or Btrfs filesystem

This partitioning allows us to boot on Legacy systems because with GPT there is still space for an MBR (for backwards compatibility reasons) and Grub2 has enough space to install some middle stage into the BIOS boot partition. Legacy BIOSes don't care about the partitioning scheme and the Grub2/Linux Kernel have no issues understanding GPT on Legacy systems.

On UEFI systems, the UEFI firmware ignores the MBR and uses the EFI system partition as entry point.

For example, with Fedora, you basically have to do the following:

Make sure that the Linux Boot filesystem is mounted under /boot and that EFI system partition filesystem is mounted under /boot/efi.

(Re-)Install both legacy and UEFI boot loaders:

grub2-pc grub2-efi-x64 shim-x64 efibootmgr

(Re-)Generate the grub config files both for legacy and UEFI boot:

# grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
# grub2-mkconfig -o /boot/grub2/grub.cfg

Depending whether your system booted in legacy or UEFI mode you have to fix either the first or second file and replace (linux|initrd)16 with (linux|initrd)efi or the other way around.

Install grub into the MBR:

# grub2-install --target=i386-pc /dev/sd_your_usb_stick_device

Voila.