Well, obviously I can, because all of the Linux distros are delivered as hybrid ISOs that can boot both BIOS and UEFI.

The question is how? I had thought I could run grub-install twice:

grub-install --target=i386-pc --recheck --boot-directory=/mnt/boot /dev/sdX
grub-install --target x86_64-efi --efi-directory /mnt --boot-directory=/mnt/boot --removable

and that it would install both. However, doesn't one clobber the other?

When it comes down to it, I don't understand enough of what grub installs in the MBR (BIOS or UEFI mode) to know. In theory, UEFI shouldn't care about the MBR itself, but just unsure.

FYI, running grub-install off of an Ubuntu LiveCD in VirtualBox because, well, because it was there.

  • 2
    To answer my own question, it does just work. I think you need to run BIOS first, then EFI, but it does work. – deitch Mar 31 '16 at 8:40

You can try this tuto_by_sysmatck_ubuntuforums.org

First Step: Format USB drive

To create a EFI firmware compatible boot drive, you need a GPT partition table and at least one FAT32 partition. Do as follows...

sudo apt-get install gdisk
sudo sgdisk --zap-all /dev/sdb

You probably need to remove and insert the USB drive again at this point for the kernel to update information about it...

sudo sgdisk --new=1:0:0 --typecode=1:ef00 /dev/sdb
sudo mkfs.vfat -F32 -n GRUB2EFI /dev/sdb1

Second Step: Copy files and Set directory structure

Let's mount the usb drive

sudo mount -t vfat /dev/sdb1 /mnt -o uid=1000,gid=1000,umask=022

To make life easier, I created a pack with all necessary files for you to modify as you need usb-pack_efi. If you don't trust my files, create yours using this page as reference.

Extract the zip file and paste those inner files using Command Line Interface or a file manager you like.

cd ~/Downloads/
unzip usb-pack_efi.zip
rsync -auv usb-pack_efi/ /mnt

The most important files are bootia32.efi to boot on 32bit machines, bootx64.efi to boot on 64bit machines and grub.cfg to setup grub to load ISOs or chainload to other paths. In the end, you might get a directory tree like this: enter image description here

Third Step: Install GRUB2 on the drive

sudo grub-install --removable --boot-directory=/mnt/boot --efi-directory=/mnt/EFI/BOOT /dev/sdb

Fourth Step: Setup ISOs to be loaded

Put (copy) the .iso files you want to load in /mnt/iso/ and setup grub.cfg like the existing examples...

Note that the most important variable to set is isofile. There is lots of examples on the web about how to configure grub2 menu. Use # to comment those lines you don't want to use, e.g. to hide a configuration of absent .iso at /iso.

Last Step: Configure firmware and Test First and most important, deactivate secure boot on your computer's firmware. Search on the web if you don't know how.

To boot the USB drive you can set your machine firmware to search first for the USB device (boot order). Or you can choose what drive to boot as soon as you turn on your computer. Each manufacturer has its own keys to do it. Search for your machine's manual if needed.

thank you sysmatck

  • 2
    Thanks for the detail... but you didn't answer about booting both BIOS and UEFI – deitch Mar 31 '16 at 10:33

Yes, you can just install Grub2 EFI and Legacy side by side. They don't clobber each other and the ordering doesn't matter.

The precondition for this to work is that you use GPT partitioning and that you have an BIOS boot partition (1 MiB is enough).

Otherwise, the legacy MBR Grub2 install will fail since there isn't enough space for its intermediate stage.

The Grub2 install commands look like this - to install into the MBR:

grub2-install --target=i386-pc /dev/sdb

And to install into the EFI system partition (ESP) it's either (after the ESP is mounted under /boot/efi)

grub2-install --target x86_64-efi

or, on Fedora-like distributions it's instead:

dnf reinstall grub2-efi-x64 shim-x64

(grub2-install works there too, but needs an additional package and breaks secure boot)

  • Been a long time since I posted this question. Since then, I have gotten very deep into the structures of filesystems, bootloaders, etc. I long since stopped using grub whenever possible, and just do simplistic loaders, except when I really need to multi-boot. Thanks! – deitch Mar 12 '18 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.