How to create a USB which boots multiple .iso files using Grub2

austintexas
  9 years ago
  8

Create a usb which boots multiple .iso files using Grub2

This method works for .isos such as Ubuntu, Linux Mint, LMDE, PCLinuxOS, Knoppix, Puppy Linux, Pinguy, Bodhi, Zorin, Gparted Live, Grub Rescue Remix, SystemRescueCD and more. It may not work for some other distros, depending on how their .iso files are structured.

These steps can be done from a live DVD or an installed linux, but preferably with an installed linux, to avoid permissions/ownership problems.

1) Prepare the usb drive:
A new usb drive should be ready to permit the installation of Grub. However, if a drive has been used to boot an iso file previously, you may get an error concerning "iso9660 filesystem", depending on how the iso boot was created. The "iso9660 filesystem" means that at some point the USB held an isohybrid image.  Since that filesystem is in the first 64 sectors of the disk, you can't delete it by deleting partitions.  You can delete all of your partitions, and it will still be there.
You can fix that with the dd command.
First, make sure you know the linux drive letter for your USB drive. You don't want to accidentally erase your hard drive. Run the following commands just to be sure you have the right drive designation.
inxi - pou or sudo fdisk -l
Since I have two internal hard drives, my USB is sdc. Yours might be sdb or sdd
Now you can erase the boot area and everything on the drive with this command
sudo dd if=/dev/zero of=/dev/sdX bs=4096
 - where X is your USB drive
It takes a long time to dd a drive, so be patient. My 8 GB drive took almost 20 minutes.

2) Configure the usb drive:
If you don't have GParted, install it > sudo apt-get install gparted
Open GParted and locate the USB drive using the drop-down menu at the top right.
Unmount the USB drive - right click > Unmount
Create a new partition table (so that you can format to ext2) - Device > Create Partition Table > msdos
Create a new ext2 partition - right click on the unallocated space > New  > Format: ext2, Label: Grub2isoUSB
-  (it can be ext2, ext3, or ext4. I use ext2 on flash drives because the lack of journaling means less wear and tear on the drive.)
Set the boot Flag - right click > Manage Flags > boot
Close GParted.
Now you have a clean USB drive ready for your .iso files.

3) Install grub2 to the USB:
 - (my USB is sdc)
Mount the USB partition: udisks --mount /dev/sdc1
Make a /boot directory: sudo mkdir /media/Grub2isoUSB/boot
Install Grub: sudo grub-install --boot-directory=/media/Grub2isoUSB/boot /dev/sdc

Take ownership of the mount point and all directories on the USB so that you can edit grub.cfg and add and remove .iso files freely:  sudo chown -R $USER:$USER /media/Grub2isoUSB
Or:  sudo chown -R yourusername:yourusername /media/Grub2isoUSB 
- edit the command for your actual user name and the correct mount point.

4) Load your .iso files:
Create a folder named "boot-isos" on the USB: mkdir /media/Grub2isoUSB/boot-isos
Copy your Mint and other .iso files into the new /boot-isos folder. You can load as many as you like - as many as the USB drive will hold.
I will use linuxmint-17-mate-dvd-32bit.iso and linuxmint-17-xfce-dvd-64bit.iso and pclinuxos64-kde-2014.05.iso as examples.

5) Create your grub.cfg:
Open gedit or your favorite text editor and create a new document.
Paste in:
# Begin /boot/grub/grub.cfg
set default=0
set timeout=8

insmod ext2
set root=(hd0,1)

menuentry "Mint 17 xfce 64bit iso" {
set isofile="/boot-isos/linuxmint-17-xfce-dvd-64bit.iso"
loopback loop (hd0,1)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject toram
initrd (loop)/casper/initrd.lz
}
menuentry "Mint 17 MATE 32bit iso - this is just a title, edit any way you want" {
set isofile="/boot-isos/linuxmint-17-mate-dvd-32bit.iso"
loopback loop (hd0,1)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject toram
initrd (loop)/casper/initrd.lz
}
menuentry "pclinuxos64-kde-2014.05.iso" {
search --set -f "/boot-isos/pclinuxos64-kde-2014.05.iso"
loopback loop "/boot-isos/pclinuxos64-kde-2014.05.iso"
linux (loop)/isolinux/vmlinuz fromusb root=UUID=68A7-EEB2 bootfromiso=/boot-isos/pclinuxos64-kde-2014.05.iso livecd=livecd apci=on splash=silent fstab=rw,noauto unionfs toram
initrd (loop)/isolinux/initrd.gz
}


Save the file on the USB drive as /boot/grub/grub.cfg

The line "set root=(hd0,1)" means sda1.  "set root=(hd2,1)" would be sdc1. For a USB drive seen as sdb, it should be "set root=(hd1,1)" I have never had to adjust that setting. It seems to work no matter what the setting is. YMMV.

The "toram" option boots the iso into ram, so if you don't have enough ram, delete that option. You need 1.5GB ram minimum.
If you do boot into ram, be very patient. It takes a long time to read the whole .iso and load it into ram. But then it is FAST !

Of course, you don't have to use both xfce and MATE. I am showing you how to do both if you want both. You can use just one, or you can add more .iso files, as many as your USB drive will hold. Just add more menu entries. To boot a different Mint .iso simply replace the /boot-isos/filename with the correct file name, and edit the menuentry line within the quote marks any way you want.

Now you can boot the USB drive with your BIOS boot menu, and the grub menu will boot the Mint iso you want.
And now you don't have a pile of DVD's that you no longer need - which is the whole point !

More sample menuentries:
Examples of GRUB2 menuentries for other operating system and utility CDs are provided on the Grub2/ISOBoot/Examples page  - https://help.ubuntu.com/community/Grub2/ISOBoot/Examples

menuentry "Rescatux iso" {
set isofile="/boot-isos/rescatux_cdrom_usb_hybrid_i386_486-amd64_0.30b7_sg2d.iso"
loopback loop (hd0,1)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject toram
initrd (loop)/casper/initrd.lz
}

menuentry "Super Grub Disk" {
set isofile="/boot-isos/super_grub_disk_0.9799.iso"
loopback loop (hd0,1)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject toram
initrd (loop)/casper/initrd.lz
}

menuentry "Gparted Live ISO" {
set isofile="/boot-isos/gparted-live-0.8.0-1.iso"
loopback loop (hd0,1)$isofile
linux (loop)/live/vmlinuz boot=live config union=aufs noswap noprompt ip=frommedia findiso=$isofile toram=filesystem.squashfs
initrd (loop)/live/initrd.img
}

menuentry "SystemRescue CD ISO" {
set isofile="/boot-isos/systemrescuecd-x86-1.5.8.iso"
loopback loop (hd0,1)$isofile
linux (loop)/isolinux/rescue64 setkmap=us isoloop=/systemrescuecd-x86-1.5.8.iso
initrd (loop)/isolinux/initram.igz
}

menuentry "Parted Magic ISO" {
set isofile="/boot-isos/pmagic-5.2.iso"
loopback loop (hd0,1)$isofile
linux (loop)/pmagic/bzImage iso_filename=$isofile boot=live load_ramdisk=1 prompt_ramdisk=0 noeject noprompt
initrd (loop)/pmagic/initramfs
}

menuentry "Clonezilla live" {
set isofile="(hd0,1)/boot-isos/clonezilla-live-1.2.8-3-amd64.iso"
loopback loop $isofile
linux (loop)/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ocs_live_run=\"ocs-live-general\" ocs_live_extra_param=\"\" ocs_live_keymap=\"\" ocs_live_batch=\"no\" ocs_lang=\"\" vga=788 ip=frommedia nosplash findiso=$isofile toram=filesystem.squashfs
initrd (loop)/live/initrd.img
}

menuentry "Gentoo 11 Live DVD" {
set isofile="/boot/iso/gentoo-livedvd-x86-amd64-32ul-11.0.iso"
loopback loop (hd0,1)$isofile
linux (loop)/boot/gentoo root=/dev/ram0 init=/linuxrc dokeymap looptype=squashfs loop=/image.squashfs cdroot initrd=/boot/gentoo.igz isoboot=/boot/iso/gentoo-livedvd-x86-amd64-32ul-11.0.iso
initrd (loop)/boot/gentoo.igz
}

Comments
jahid_0903014 9 years ago

It seems to be better than using multisystem or multibootusb...


MagicMint 9 years ago

That’s a nice idea for a showcase of different distros to test!