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

biosbootlinuxuefiusb

my idea is to create an USB-Boot-Stick with Lubuntu that is able to boot on an older BIOS Laptop and an newer UEFI Systems.

This would be quite easy, when the Stick would be setup as a legacy boot device, but I want it to be an UEFI-able device.

  1. Does that make even sense?! Or did I understand the UEFI concept horrobly wrong?
  2. If necessary there can be two diffrent Linux installs (one for UEFI, one for legacy but both on the same drive)
  3. Boot a GPT Device on legacy Bios – will that work?

I can't see clear, it might be just a better idea to have a seperate legacy Linux boot stick, but I am curious to explore the boundries πŸ™‚

So, is my idea of a hybrid linux-uefi-boot-usb-stick that would work with legacy bios possible?


(3) seems to be possible for linux with grub http://www.rodsbooks.com/gdisk/booting.html

Further, I do have an EF00 Partition ready on that stick, aside a Swap, Fat32 and two Ext4 partitions.


(1) seems to be possible too http://www.rodsbooks.com/bios2uefi/

This instructions are however from 2012, some time passed since – does anybody have a working example that is easier?


For other researchers of this topic:

Boot of Windows 7 from GPT disk on non EFI motherboard
Is there any way to boot Windows 7/8 using BIOS on GPT?

http://www.borncity.com/blog/2012/07/25/uefi-emulation-auf-pcs/


UPDATE:

I have managed to create the UEFI part inlcuding secure Boot setup with rEFInd.

Following the given advice, I have used dd to copy gptmbr.bin to my drive, which now seems to do at least something on a BIOS-System: "This is not a bootable disk"

However, I have followed the advice and set the pmbr flag for the disk and the gpt legacy boot flag – still gettin this error, any ideas?

My ESP partition is the second partition on the disk and is setup with efi files.

The Setup:

  • 64GB Space
  • GPT Partitiontable
  • Disk has pmbr flag set
  • 1st Partition starts at 16MiB and is about 45GB, a fat32 primary for data
  • 2nd Partition starts around 45GB and is the EFI System(fat32) with a working rEFInd setup
  • 3rd – 5th Partition is home (ext4), swap and root(ext4) of my working Lubuntu 14.04.1

Using dd I have copied the gptmbr.bin of my compiled 6.02 Syslinux to the first 440bytes.

Under parted 3.2 I can see that my partition 2 has a boot and legacy_boot flag.

During boot I get No bootable disk found – if I set my 5th instead of the 2nd partition to be legacy_boot I get Missing OS

It's alive!

(As my old Question got deleted https://askubuntu.com/q/516730/319747)


My guess is, that I have to copy some of the *.c32 and other files
to a syslinux folder eighter on my EFI (where?!) or on my root
partition (/boot/syslinux?!) to get it to work – am I right? What
files are essential?

Further, I guess I will need that syslinucx.cfg file too – right?


My goal would be at least a direct boot of the lubuntu system on the
root ext4 partition.

Update:

Although I have no idea why, I got it working – but not with a manual
install.

  • the pmbr flag was bad and prohibited my UEFI system from booting the stick as UEFI
  • the legacy_boot flag was necessary for my 5th partition (linux root)
  • I had to use extlinux --install /path/to/root/parition
  • I had to create a syslinux.cfg in the syslinux folder under boot of my root partition

I did all of this on a second smaller stick, then tried to copy just
the syslinux folder, but had no luck – the extlinux --install seems
to be mandatory.

Anybody knows what exactly extlinux --install does? Can it be done
manually or how else could you install a newer version like 6.02
without installing it on to your system?

Got my stick working with the partitions mentioned on BIOS, UEFI and UEFI SecureBoot, hell of a ride, learned a lot, nearly killed 2TB with parted, be careful and good luck.

Best Answer

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.