A script suite to create multiboot USB stick for GNU/Linux distributions
liveusb-builder is a script suite to create multiboot USB stick for GNU/Linux distributions. It's lightweight with few dependencies, and it's extensible and hackable.
The source code is hosted on both git.wehack.space and GitHub.
A presentation in Chinese is at https://wehack.space/vimacs/liveusb-builder.odp.
You need these packages on your GNU/Linux system to use liveusb-builder.
For Arch Linux users, just install liveusb-builder-git from AUR.
liveusb-builder needs a kernel image, an initramfs image, and a proper kernel command line to support a boot image. However, not every CD/DVD image supports booting this way. There are some other ways to boot these images, but they will break our philosophy to support various firmware and bootloaders.
If you want to use a disk image to install an operating system, I suggest using the virtual machine method as follows. Boot an AMD64 machine with enough memory and VMX feature with a Live USB with QEMU GUI (e.g. Grml 2020.06, also see my ticket for Grml) after attaching the hard disk you want to install the OS on, then run the following (assume the hard disk attached is /dev/sda):
sudo qemu-system-x86_64 -enable-kvm -m 4G -cdrom your-install-cd.iso -drive /dev/sda,format=raw -boot order=d -no-reboot
Do the system installation in the QEMU window. After QEMU exits, put the hard disk on the target machine to continue installing.
I've already used this method to successfully install Windows 7, OpenBSD 6.7, and various GNU/Linux systems.
First, you need to have a partitioned USB drive. For the best legacy BIOS compatibility, it's recommended to use MSDOS (MBR) partition table. Because most UEFI firmware only supports FAT32 partitions, you need a FAT32 partition on the USB drive, and put the boot files into this partition.
Suppose your USB stick device is /dev/sdb and the partition on the device is /dev/sdb1.
# install Arch, Mint (x86_64 with MATE Desktop) and Fedora 32 to USB
./buildlive --root=/dev/sdb1 arch mint/mate fedora/32
The other way is to mount your USB drive partition first. I recommend using udevil so that you can write files without as root. Then run buildlive script as follows, suppose /dev/sdb1 is mount to /media/sdb1:
# install Arch, Mint (x86_64 with MATE Desktop) and Fedora 32 to USB
./buildlive --root=/media/sdb1 arch mint/mate fedora/32
Partition your disk as follows to create a 500MB FAT32 boot partition, and an ext2 partition using the remaining space, suppose your USB is /dev/sdb.
$ sudo fdisk /dev/sdb
Command (m for help): o
Created a new DOS disklabel with disk identifier 0x24c5dd70.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1):
First sector (2048-30463999, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-30463999, default 30463999): +500M
Created a new partition 1 of type 'Linux' and of size 500 MiB.
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): b
Changed type of partition 'Linux' to 'W95 FAT32'.
Command (m for help): a
Selected partition 1
The bootable flag on partition 1 is enabled now.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (2-4, default 2):
First sector (1026048-30463999, default 1026048):
Last sector, +sectors or +size{K,M,G,T,P} (1026048-30463999, default 30463999):
Created a new partition 2 of type 'Linux' and of size 14 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
Format the partitions:
sudo mkfs.msdos -F 32 /dev/sdb1
sudo mkfs.ext2 /dev/sdb2
Mount them and create the directory, and we need to make the directory liveusb-data
writable by the current user.
udevil mount /dev/sdb1 /media/boot
udevil mount /dev/sdb2 /media/root
sudo install -d /media/root/liveusb-data
sudo chown $(whoami) /media/root/liveusb-data/
At last, make the Live USB (we install Arch and Fedora 32 in it):
$ ./buildlive --boot /media/boot --root /media/root arch fedora/32
I've made some experimental features that are not yet merged to the main source tree.
The resulting USB stick works on QEMU with PC BIOS (SeaBIOS), UEFI (OVMF), libreboot (i440fx, GRUB txtmode) as firmware.
The script testusb.sh
can be used to test a USB stick with QEMU.
You can search keyword multiboot
on GitHub and find some related projects. Listed below is some related work I know or find.