This small Howto is about setting up a USB stick to boot different iso files using grub's loopback capability. I only tested this on Fedora, but it should also work on other Linux distributions.
lsblk
This should give you a list of all your block devices. My stick is found as /dev/sdc
- we will use gdisk
sudo gdisk /dev/USBDEV
- create a new empty partition table by pressing
o
- create a new partition by pressing
n
- use the default start point by just pressing enter
- make it 2 megabytes big by entering
+2M
- enter
ef02
as the type of the partition to make it a Bios boot partition - create another partition by pressing
n
- let it start at the default by pressing enter
- let it use the maximum available size by pressing enter again
- enter
0700
as its type to make it a Microsoft basic data partition
- use
partprobe
to update your partition tables without rebooting - next run
mkfs.vfat /dev/USBDEV2
- first mount the stick:
mount /dev/USBDEV2 /mnt
- first install grub for non-uefi systems use
grub2-install --target i386-pc --removable --boot-directory=/mnt
- then install grub for uefi systems use
grub2-install --target x86_64-efi --efi-directory /mnt --removable --boot-directory /mnt
- create the file
/mnt/grub2/grub.cfg
with the following contents:
insmod font
if loadfont ${prefix}/fonts/unicode.pf2 ; then
# Use shift key to avoid loading gfxterm
if keystatus --shift ; then true ; else
insmod gfxterm
insmod vbe
insmod vga
set gfxmode=auto
set gfxpayload=auto
terminal_output gfxterm
if terminal_output gfxterm ; then true ; else
terminal gfxterm
fi
fi
fi
set color_normal=white/black
set color_highlight=white/light-blue
export color_normal
export color_highlight
echo "Generating entries from *.cfg files"
insmod regexp
for cfg_file in /isos/*.cfg /isos/*.CFG; do
echo "sourced $cfg_file"
source $cfg_file
done
menuentry "Reboot" {
reboot
}
menuentry "Poweroff" {
halt
}
- create the folder
/mnt/isos
- put all the iso files you want to be able to boot in it
- create a config for each in the same folder, named
<something>.cnf
A sample config file for Fedora 21
menuentry "Fedora 21" {
set iso_path="/isos/Fedora-Live-Workstation-x86_64-21_Beta-4.iso"
loopback loop $iso_path
linux (loop)/isolinux/vmlinuz0 iso-scan/filename=$iso_path root=live:CDLABEL=Fedora-Live-Workstation-x86_64-2 rootfstype=auto ro rd.live.image quiet rhgb rd.luks=0 rd.md=0 rd.dm=0 nomodeset
initrd (loop)/isolinux/initrd0.img
}
menuentry "Fedora 21 (uefi)" {
set iso_path="/isos/Fedora-Live-Workstation-x86_64-21_Beta-4.iso"
loopback loop $iso_path
linuxefi (loop)/isolinux/vmlinuz0 iso-scan/filename=$iso_path root=live:CDLABEL=Fedora-Live-Workstation-x86_64-2 rootfstype=auto ro rd.live.image quiet rhgb rd.luks=0 rd.md=0 rd.dm=0 nomodeset
initrdefi (loop)/isolinux/initrd0.img
}
- for UEFI:
qemu-system-x86_64 -L /usr/share/qemu-ovmf/bios -hda /dev/USBDEV
- for BIOS:
qemu-system-x86_64 -hda /dev/USBDEV