How to Create a Multiboot USB Compatible with BIOS and UEFI

dual-bootgrub2live-usbuefi

Right now, I have created a drive using Yumi's UEFI program to create a multi-boot USB for UEFI, but as of late, I need a BIOS one as well. Is there a way to combine those two into one drive? Basically supporting UEFI AND BIos? Or will I need two different USB's? Thanks!

Best Answer

MultiBoot USB Stick from Scratch

(Modification of How do I boot an ISO file from my drive using grub2 on UEFI machines?)

GParted Partitions

GParted

  • Create a gpt partition table on a USB stick.

  • Create partitions as shown above, select unformatted for partition 2.

  • Create a casper-rw file:

    sudo dd if=/dev/zero of=casper-rw bs=1M count=512

    sudo mkfs.ext3 -L casper-rw -F casper-rw

(where count=512 is the persistence size in megabytes, with a max of 4GB).

Persistence partition

Persistence Partition

  • Create an uniquely name folder for each OS, (that requires persistence), on the USB-PRST partition.

  • Add a casper-rw file, (and optional home-rw file), to each persistence folder. A home-rw file can be made by renaming a casper-rw file. A home-rw file is like a separate home partition on a Full install, it can be reused after version upgrades.

Data Partition

Data Partition

  • Create a folder for the ISO files on the NTFS USB-DATA partition.

  • Add some ISO's to the isos folder.

Boot Folder

Boot Partition

  • Open the latest ISO file and copy the boot and the EFI folders to the USB-BOOT partition. Add rmmod tpm to grub.cfg above the first menuentry

  • Install grub

    sudo mount /dev/sdx3 /mnt

    sudo grub-install --boot-directory=/mnt/boot /dev/sdx

Edit grub.cfg to loopmount the ISO files. Include: persistent persistent-path=/<persistent-folder-name>/ if you want multiple persistence.

if loadfont /boot/grub/font.pf2 ; then
    set gfxmode=auto
    insmod efi_gop
    insmod efi_uga
    insmod gfxterm
    terminal_output gfxterm
    rmmod tpm
fi

set menu_color_normal=white/black
set menu_color_highlight=black/light-gray

set timeout=5

menuentry "ubuntu-19.10-desktop-amd64.iso" {
    set root=(hd0,1)
    set isofile="/isos/ubuntu-19.10-desktop-amd64.iso"
        loopback loop $isofile
        linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile persistent persistent-path=/persist-1/ splash --
        initrd (loop)/casper/initrd
}
menuentry "lubuntu-16.04.3-desktop-amd64.iso" {
    set root=(hd0,1)
    set isofile="/isos/lubuntu-16.04.3-desktop-amd64.iso"
        loopback loop $isofile
        linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile persistent persistent-path=/persist-2/ splash --
        initrd (loop)/casper/initrd.lz
}

Grub.cfg example

sudo parted -ls  /dev/sdx

sudo parted -ls /dev/sdx

sudo lsblk -f  /dev/sdx

sudo lsblk -f /dev/sdx

If the above is used as a USB stick it can be used to boot ISO's stored on a Windows only computer. Grub is not required on the internal drive.