grub: boot from ISO

The biggest problem with booting an ISO file is that ISOs that are designed to be booted are almost always designed to be booted from a CD. As explained on Marco's blog regarding Grub 2 (emphasis mine):

GRUB can read ISO9660 (”iso”) images. It can for example load the first few sectors and boot it. But most people do not realize is “what then?”. What would the loaded operating system do? It will most likely look for a CDROM, which it won’t find, and fail.

So the dead-simple-est way to boot from some random ISO file is to load it into a virtual machine (VirtualBox, VMware, or Virtual PC) as a virtual CD and boot it there. That should almost always work, because to the VM, it's not an ISO file -- it's a real CD on real CD hardware.

Booting from an ISO file on bare metal is much harder. How you do this depends on which version of Grub you're using, and results can differ depending on what ISO you're using and how it was configured to boot. This is why most boot-ISO-from-USB tools (Unetbootin, WinToFlash, etc) usually extract the ISO contents to the drive -- because that way they can be accessed directly, without confusing the OS being booted.


Grub 1

... not sure. If possible, menu entries will probably look a lot like Grub4DOS, though I think the "map --hook" command is a Grub4DOS enhancement. On the plus side, Grub has wider filesystem support than Grub4DOS.

A note on Grub with reiserfs (unconfirmed) indicates you "have to mount your partition with notail for it to work".

Memdisk is an option; see below.


Grub4DOS

Grub4DOS offers some experimental "CD emulation" that works with some ISOs. Unfortunately, Grub4DOS only reads FAT32/NTFS filesystems. Download Grub4DOS.

Here's a sample entry (source):

title fdfullcd.iso (0xFF)
  find --set-root /fdfullcd.iso
  map /fdfullcd.iso (0xFF)
  map --hook
  root (0xFF)
  kernel /isolinux/data/memdisk
  initrd /isolinux/data/fdboot.img

Supposedly the Win7 ISO can be booted with this entry:

title Windows 7
  map (hd0,0)/win7.iso (hd32)
  map --hook
  chainloader (hd32)

Other ISOs can be booted with Memdisk:

title Boot Hardware Detection Tool from iso image (with 'iso' parameter)
  kernel /memdisk iso
  initrd /hdt.iso

You can also use a menu configurator like MultiBootISOs.exe from PenDriveLinux. Place ISOs on the flash drive, and run the utility to install the bootloader and configure the boot menu.

Here's a Hak5 episode on installing Grub4DOS.


Grub 2

Here's a couple of example Grub2 entries. chainloader doesn't work to boot an ISO at present, so these entries must (1) use loopback to "mount" the ISO, and (2) add something like iso-scan or findiso to the linux line that specifies the ISO file.

Unfortunately, there's no generic way to do this. Each different boot entry must be customized to the target ISO's contents. Most Linux LiveCDs use ISOLINUX as a bootloader; find the isolinux.cfg and examine that boot entry to see what it usually boots.

Example entries (source):

menuentry "Ubuntu Live 9.10 32bit" {
 loopback loop /boot/iso/ubuntu-9.10-desktop-i386.iso
 linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/boot/iso/ubuntu-9.10-desktop-i386.iso noeject noprompt --
 initrd (loop)/casper/initrd.lz
}

menuentry "Grml small 2009.10" {
  loopback loop /boot/iso/grml-small_2009.10.iso
  linux (loop)/boot/grmlsmall/linux26 findiso=/boot/iso/grml-small_2009.10.iso apm=power-off lang=us vga=791 boot=live nomce noeject noprompt --
  initrd (loop)/boot/grmlsmall/initrd.gz
}

If you're trying to boot a non-Linux LiveCD, you may be out of luck. Again, Memdisk may help:

menuentry "Boot Hardware Detection Tool from iso" {
  linux16 /memdisk iso
  initrd16 /hdt.iso
}