GRUB script to boot various Linux live CD/DVD images
- Your target device, like a USB flash drive, should be formatted as FAT(32).
- That's because (most) UEFI/EFI supports only FAT(32), if you target BIOS systems only, you can use ext4/btrfs/exFAT/NTFS, or whatever grub supports.
- Install GRUB(2, not legacy) on your target device:
(assuming your USB drive is
/dev/sdband mounted on
- For UEFI/EFI x64 systems:
grub-install --target=x86_64-efi --boot-directory=/mnt/usb/boot /dev/sdb
- For BIOS systems:
grub-install --target=i386-pc --boot-directory=/mnt/usb/boot /dev/sdb
- You can install both.
- Alternative way for UEFI/EFI x64 systems:
grub-mkimage -o bootx64.efi -O x86_64-efi -p /boot/grub \ boot linux linux16 chain normal configfile \ part_gpt part_msdos fat iso9660 udf \ test true keystatus loopback regexp probe \ efi_gop efi_uga all_video gfxterm font \ echo read help ls cat halt reboot
- For UEFI/EFI x64 systems:
grub.cfgfrom this repository in
- Put image files in
- Boot from this device, that depends on your system/motherboard vendor.
- On some modern PCs, you can press F12 to select from a list of boot devices during POST.
- Configure BIOS/EFI to boot from this device.
- More detailed document from Debian.
- Debian Live
- And some Debian derivatives like:
- And some Ubuntu derivatives like:
- And some Arch derivatives like:
- Fedora Live
- Only tested on workstation live image.
- Both the live and installer(like Minimal) images are supported.
- There is no live image, the installer image is supported though.
GRUB is not able to do image boot on its own, the image boot procedure can be loosely described like this:
- GRUB loop mount the image, load the Linux kernel and initrd from it.
- the loopback command.
- GRUB boot the kernel, passing the initrd along with some parameters including the location of the image.
- Some script in initrd loop mount the image and continue the rest of the boot procedure.
So, if the initrd itself doesn't implement this mechanism, it won't work(hence the unsupported section).
And in step 2, different distributions tends to use different parameter schemes, this is where this script kicks in: it tries to determine the image vendor and feeds appropriate parameters accordingly.
Comparing with other methods:
The official way to make a bootable live USB drive suggested by most distributions is dd the image, those images are cleverly made FAT/ISO9660 hybrids so they work that way, depends on almost nothing, simpler to setup but also monogamy, destroys all data on the drive and the rest of the drive is not usable.
There are tools to put multiple distributions on a single USB drive, but mostly they are Windows only and they extract the image contents to the USB drive so they are slower, and needs to run the tool every time you want to add/remove a image.
Using this script, once the initial setup is done, you can simply copy/delete the image file, compatibility is not 100% but considerably usable.
- Debian Installer, initrd in the image doesn't support loop,
but Debian provided an alternative initrd,
(USB)/boot/debian-installer/amd64/and your choice of installer image (like this) to
- Do not mix arch, for example you should use amd64 image with amd64 kernel and initrd.
- Do not use live images.
- Official document about this method is here.
- EFI binary chainloading, simply copy to
(USB)/efi/*/bootx64.efi, useful examples like:
- Proxmox VE, it's based on Debian but the boot script is their own, too bad this is one of my favorite distributions.
- Mageia, doesn't have loop mount in initrd.
- LXLE, it is actually a lubuntu derivative, while lubuntu works like other Ubuntu derivatives, it doesn't, strangely.