How to create a Multiboot ISO with Grub2

Thursday, October 8, 2009
Edit(March 17 2011): I now use Multisystem.


Edit: Before you read this article, You should be aware that This method only works when burned to a cd/dvd or by using the iso file in a virtual machine. I have used the Ubuntu USB Startup Disk Creator as well as Unetbootin and I haven't figured out how to make things work just yet. Please bookmark the link to this article and I will update as soon as I get everything working.


I have been playing with grub2 and booting linux iso files since I watched episode 602 of Hak5.
This method is attractive to me bacause I do not need a separate usb stick for each distro I want to play with or install. I could have a 16 gig usb stick with 20 distros or more on it if I wanted to. I have found a way that is fairly simple to install grub2 to my usb stick and boot linux iso's with the "loopback" option of grub2. There is a package in Ubuntu called grub-rescue-pc.
You can install this software by issuing the command
sudo apt-get install grub-rescue-pc
Or by using synaptic if you prefer.
While we are at it why don't we install qemu and isomaster as well.
sudo apt-get install isomaster qemu
After installing this package there will be two files in /usr/lib/grub-rescue. The grub-rescue-cdrom.iso is the file that we will be using. This file contains a bootable image of grub2. We can also edit this image file with a program called Isomaster (also available in the repositories). If you prefer, you can install the grub image onto the usb by using the ubuntu 'usb-creator' or unetbootin.
This will make the editing and adding of iso files easier but to test the end result you will need to reboot your pc every time. Time can be saved by editing the grub2 iso image directly and testing the file with Virtualbox, VMWare or Qemu yada, yada, yada. Pick your poison.

After you have installed grub-rescue-pc, Virtualbox and Isomaster, we can open up the grub-rescue-cdrom.iso image with Isomaster. In the directory "/boot" of the grub2 image you will need to create a folder called "iso". Once the folder exists you can now add your linux iso files in this folder. It is as easy as browsing to the iso file that you want to add in the top pane of the program and clicking on the Add button. Now that you have some distros in there, let's see if we can make them work.

The file we will be editing is /boot/grub/grub.cfg of the grub2 image file. Not the one installed on your hard drive. (This can be done within Isomaster)
I used this site as a reference for the distributions that I am playing with.
Just under the line that says:

# For booting GNU/Hurd
you can start to add entries for your distros that you want to boot.

I decided to try Ubuntu 9.04 (32 bit) as well as Ubuntu 9.04 (64 bit).
Here are my two entries that allow them to load.

menuentry "Ubuntu Live 9.04 32bit" {
loopback loop /boot/iso/jaunty-desktop-i386.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/boot/iso/jaunty-desktop-i386.iso --
initrd (loop)/casper/initrd.gz
}

menuentry "Ubuntu Live 9.10 64bit" {
loopback loop /boot/iso/karmic-desktop-amd64.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/boot/iso/karmic-desktop-amd64.iso --
initrd (loop)/casper/initrd.lz
}

Notice that the last line for each entry is different. Ubuntu 9.04 says /casper/initrd.gz and the Ubuntu 9.10 says /casper/initrd.lz . This is important, so if you do any editing, keep this in mind. You can make your own entries for other distrobutions as you wish. Once you are satisfied you will have to save the image as a new iso file.( this will be the one you will load to your usb drive.

I find the easiest way to test the end result is with qemu. It loads fast and your results are prety much instant. I have also made a nautilus script so that I can launch an iso with qemu right from the right click context menu.
Here is the script
qemu -cdrom $* -boot d
If you want to allocate a certain amount of memory to the virtual machine add " -m 700". This will allow 700 mb of system memory to be used by the vm. Place this in a text file. Name it qemu-livecd and save it to ~/.gnome2/nautilus-scripts/ and make it executable. Now when you right click on the iso file go to Right Click>Scripts>qemu-livecd.

Once your configuration is complete and you have tested that all of the menus work you can load the image to your usb stick using unetbootin or the ubuntu USB Startup Disk Creator. Or your favorite app that you normally use for this task.

If you decide later that you want to update any of the distributions on your usb stick you can just plug it in to your pc and replace the iso files with the new ones. Pretty simple huh?

If there is anyone that wants to make a gui for this, please let me know.




4 comments:

Katz said...

I have followed your instructions to the letter. the only problem is that if I try to use USB startup disk creator it tells me that I cannot use that ISO. if I use unetbootin it works but boots to a screen that says unetbootin. the problem is that the unetbootin has no options just default that doesn't load anything.

Drew DeKoning said...

I have had simillar results. I am looking into it and maybe I will try burning the grub iso to usb first.

Unknown said...

might there also be a way to toss in winxp with virus scanning potential?

luftiq said...

You can also use automated tools like xboot. See tutorial here: http://www.kimpl.com/?p=202