How To Create Multi-boot USB Drive Without Ventoy - GRUB FTW

How To Create Multi-boot USB Drive Without Ventoy - GRUB FTW
Photo by Arun Prakash / Unsplash

Why GRUB

GRUB is the standard Linux bootloader for decades, and also supports other operating systems. Ventoy, another popular Open Source tool made by Chinese developer Hailong Sun, does the job really straightforward and doesn't need any dancing with configs. So, why do we still need Grub? There are several reasons:

GRUB2 supports more file systems like Btrfs and F2FS and much more configuration options. Next use cases are possible:

  • all files on single partition - easy to use
  • all iso images can be located in one directory
  • add/delete images is easy - the file tree under user control

How to install

Detect the target device by size:

$ fdisk -l

Create a new partition table if needed:

# parted /dev/sdX
(parted) mklabel msdos

Create new partition:

For BIOS/MBR:
(parted) mkpart primary vfat 4MiB 100%
(parted) set 1 boot on

Install Grub2:

# mount /dev/sdX /mnt
# mkdir /mnt/boot

# BIOS
# grub2-install --target=i386-pc --recheck --boot-directory=/mnt/boot /dev/sdX

# UEFI
# grub2-install --target x86_64-efi --efi-directory /mnt --boot-directory=/mnt/boot --removable

Now we can copy the images to a flash drive, they can be located anywhere.

$ ls -a /mnt/boot/*iso
/mnt/boot/elementaryos.iso
/mnt/boot/Fedora.iso
/mnt/boot/linuxmint.iso
/mnt/boot/tails.iso
/mnt/boot/ubuntu.iso

And setup the Grub2 config:

cat /boot/grub2/grub.cfg
# /boot/grub/grub.cfg - Grub2 config

insmod part_msdos
insmod part_gpt
insmod ext2
insmod iso9660
insmod fat

# Get UUID of USB Flash with `$ lsblk -f` command:
# 56f48195-f142-4df4-84cf-5a21f29177c4

search --no-floppy --fs-uuid --set=root 56f48195-f142-4df4-84cf-5a21f29177c4
menuentry 'Ubuntu' {
	set isofile='/boot/ubuntu.iso'
	loopback loop $isofile
	linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile locale=en_US.UTF-8
	initrd (loop)/casper/initrd.lz
}

menuentry 'elementaryos' {
	set isofile='/boot/elementaryos.iso'
	loopback loop $isofile
	linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile locale=en_US.UTF-8
	initrd (loop)/casper/initrd.lz
}

menuentry "Linux Mint" {
    set iso=/boot/linuxmint.iso
    loopback loop $iso
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$iso noeject noprompt
    initrd (loop)/casper/initrd.lz
}

menuentry "Tails" {
    set isofile='/boot/tails.iso'
    loopback loop $isofile
    linux (loop)/live/vmlinuz2 boot=live config findiso=${isofile} live-media=removable apparmor=1 security=apparmor nopersistent noprompt timezone=Etc/UTC block.events_dfl_poll_msecs=1000 noautologin module=Tails
    initrd (loop)/live/initrd2.img
}

	menuentry 'Fedora Workstation' {
	set isofile='/boot/Fedora.iso'
	loopback loop $isofile
	linux (loop)/isolinux/vmlinuz0 root=live:CDLABEL=Fedora-Live-WS-x86_64 iso-scan/filename=$isofile rd.live.image
	initrd (loop)/isolinux/initrd0.img
}

Now time to unmount the flash drive and reboot for testing.

Sometimes there's a task to boot not popular image and Internet isn't helpful. The only one way is to dive deeper into the image itself and figure it out.

  • isoscan/filename - we need the path for image boot menu.
  • linux ... - unique additional boot parameters.

Let's mount the iso image and check the configuration we need for a successful boot:

$ sudo mount -o loop /path/to/iso /mnt/

isolinux or boot/isolinux are two popular locations to check boot configuration. We need something like

label live
menu label Try Ubuntu without installing
kernel /casper/vmlinuz.efi
append file=/cdrom/preseed/ubuntu.seed boot=casper
initrd=/casper/initrd.lz quiet splash

The kernel parameter contains the Linux option for the linux (loop)..., the same with initrd path. append file should be added to linux (loop)... line.

Some Linux distributions use a parameter isolabel, it can be obtained from isoinfo command output: isoinfo -d -i image.iso.

  • Glim, a set of grub configuration files to turn a simple VFAT-formatted USB memory stick with many GNU/Linux distribution, supports Antergos, Antix, Arch, Bodhi, Centos, Clonezilla, Debian, Elementary, Fedora, IPXE, Kali, Linuxmint, Manjaro, Ubuntu, Void and more.
  • AIO Boot - All-in-One bootable software for USB and HDD, supports Clover, rEFInd, Grub4Dos, Enoch Chameleon and Syslinux. Many Windows and Linux images are supported too.

Read more