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/sdc
- create a new empty partition table by pressing
o
- if it asks for a confirmation press
y
- create a new partition by pressing
n
- use the default partition number by pressing enter
- use the default first sector by 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
- use the default next partition number by pressing enter
- use the default first sector 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 - verify the partitions are created by pressing
p
Number Start (sector) End (sector) Size Code Name 1 2048 6143 2.0 MiB EF02 BIOS boot partition 2 6144 30529502 14.6 GiB 0700 Microsoft basic data
- write the changes by pressing
w
- answer yes to the confirmation by pressing
y
- now unplug the usb stick for 10 seconds and plug it back in
- ensure that the partition table has been updated:
$ fdisk -l /dev/sdc Disk /dev/sdc: 14.6 GiB, 15631122432 bytes, 30529536 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: F2A83318-983E-4547-86C9-7C1301FFFE0B
Device Start End Sectors Size Type /dev/sdc1 2048 6143 4096 2M BIOS boot /dev/sdc2 6144 30529502 30523359 14.6G Microsoft basic data
- in this case, /dev/sdc2 is the data partition
- next run
sudo mkfs.vfat /dev/sdc2
- first mount the stick:
sudo mount /dev/sdc2 /mnt
- next install grub for non-uefi systems use
sudo grub2-install --target i386-pc --removable --boot-directory=/mnt
- then install grub for uefi systems use
sudo 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