MultiBoot USB
This is a collection of GRUB scripts that allows to create a bootable pendrive (USB dongle, flash stick) supporting a number of different OS images. Simply copy ISO files under `/iso-imgs`. Both UEFI and Legacy BIOS boot modes can be enabled simultaneously.
If we have Git installed on the system, we can get the files directly from the repository:
git clone https://github.com/ulidtko/multibootusb
After this, every time we want to update the files we do:
cd multibootusb && git pull
If Git is not installed, we can still get the files as long as we have a basic Unix environment available:
wget https://github.com/ulidtko/multibootusb/archive/opensource.tar.gz -O - | tar -xzv --strip-components 1 --exclude={README.md,docs}
We must have the files for targets i386-pc (e.g. package
grub-pc-bin
in Debian/Ubuntu) and x86_64-efi (e.g. package
grub-efi-amd64-bin
in Debian/Ubuntu) available in the system, usually in
/usr/lib/grub/
.
Follow the instructions to create a Hybrid UEFI GPT + BIOS GPT/MBR boot from the ArchWiki.
Set variables to avoid errors:
export mntusb=<mountpoint> partusb=<partition>
Where
<mountpoint>
is any directory you want the partition to be mounted at (e.g.
/media/usb), and
<partition>
is the name of the data partition (e.g. /dev/sdh3). Run
dmesg
to get
this information.
Mount the data partition:
mount --target $mntusb $partusb
Create a directory named boot to store GRUB’s configuration files and a directory named isos for the kernel/ISO files:
mkdir -p $mntusb/boot/{grub/mbusb.d/,isos}
Copy the necessary GRUB files:
cd multibootusb && cp -rf mbusb.* $mntusb/boot/grub/
Copy the provided
grub.cfg
:
cp -f grub.cfg.example $mntusb/boot/grub/grub.cfg
Download MEMDISK from kernel.org:
wget -qO - 'https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz' | tar -xz -C $mntusb/boot/grub/ --no-same-owner --strip-components 3 'syslinux-6.03/bios/memdisk/memdisk'
Simply run as root:
./makeUSB.sh <device>
Where
<device>
is the name of the USB device (e.g. /dev/sdh). Run
mount
to get
this information.
WARNING: This will delete all data in the device, so make sure you pick the right one.
These are the options for the script:
Script to prepare multiboot USB drive
Usage: makeUSB.sh [options] device [fs-type] [data-size]
device Device to modify (e.g. /dev/sdb)
fs-type Filesystem type for the data partition [ext3|ext4|vfat|ntfs]
data-size Data partition size (e.g. 5G)
-b, --hybrid Create a hybrid MBR
-c, --clone Clone Git repository on the device
-e, --efi Enable EFI compatibility
-i, --interactive Launch gdisk to create a hybrid MBR
-h, --help Display this message
If you already have your own bootable USB drive that uses GRUB to
boot, you can simply add the following lines into your custom
grub.cfg
:
# Load MBUSB configuration
if [ -e "$prefix/mbusb.cfg" ]; then
source "$prefix/mbusb.cfg"
fi
And then copy the project’s configuration files to your drive’s GRUB directory:
cd multibootusb && cp -rf mbusb.* $mntusb/boot/grub/
Once you have a bootable USB drive, it only remains to copy the
bootable files (ISO or kernel) to the pendrive. See the
list of supported files for download links and
then save them into
$mntusb/boot/isos
.
QEMU provides a virtual environment capable of booting directly from the newly created USB drive.
In most installations, the Legacy PC BIOS mode will work by default with no additional setup, run:
qemu-system-x86_64 -enable-kvm \
-rtc base=localtime -m 1G -vga std \
-drive file=<device>,readonly,cache=none,format=raw,if=virtio
Testing UEFI boot mode is also possible with an additional firmware called Tianocore OVMF (not included with QEMU):
qemu-system-x86_64 -bios /usr/share/ovmf/x64/OVMF.fd \
-rtc base=localtime -m 1G -vga std \
-drive file=<device>,readonly,cache=none,format=raw,if=virtio
As usual, substitute
<device>
with the name of the USB device (e.g. /dev/sdh).