grub: boot from ISO

41

31

How can I boot into an ISO file in GRUB? The ISO file is on a reiserfs partition and GRUB can access it (already tested that).

Albert

Posted 2010-06-18T14:25:36.080

Reputation: 5 059

1

Ubuntu: http://askubuntu.com/questions/340156/install-ubuntu-from-iso-image-directly-from-hard-disk-of-a-system-running-linux

– Ciro Santilli 新疆改造中心法轮功六四事件 – 2015-08-24T10:16:09.867

which version of grub? – quack quixote – 2010-06-18T17:08:04.180

See also installation - Install Windows 7 from ISO image - Super User for Windows ISO.

– user202729 – 2019-08-14T15:47:00.033

1

The same question answered here.

– dma_k – 2014-05-12T10:07:59.253

Answers

55

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
}

quack quixote

Posted 2010-06-18T14:25:36.080

Reputation: 37 382

1@quackquixote, Regarding your bolded words "What would the loaded operating system do? It will most likely look for a CDROM, which it won’t find, and fail", Why does the OS need to look for a CDROM? It's already a perfect iso file and the everything that is needed to load the OS is already within the iso file, so why can't it skip looking for CDROMs? – Pacerier – 2015-04-26T20:42:28.943

@Pacerier I was thinking the exact same thing. It's not like any of my computers have CDROMs anyway--so why don't they all fail to boot? – Angelo – 2016-05-11T03:48:27.680

@albert: i'm using Grub2 on a flash drive and been frustrated by the same things, so it wasn't hard putting together. i'm looking into your other question, but i've never tried "burning" an ISO onto a partition before, so it may be... interesting. – quack quixote – 2010-06-18T18:54:25.107

Ofc I can boot it inside VMware (and I also already did) but that doesn't help me much because it is Windows and when I install it via VMware on my disk, it wont boot later on (stupid Windows...). – Albert – 2010-06-18T19:00:26.387

Can you give me a suggestion what option I should try first, i.e. Grub1, Grub2 or Grub4DOS? I can just install whatever is needed, that wont really be the problem. – Albert – 2010-06-18T19:01:50.067

@albert: are you asking in reference to your earlier question? i believe your best bet is to use the extraction method; the Windows installer is one of those ISOs that have problems when they aren't booted from hardware. you can try memtest, but i don't know much about it. you probably want to get a flash drive and use that; see http://superuser.com/questions/66948/place-a-bootable-iso-on-a-usb-drive or http://superuser.com/questions/62193/install-win7-from-usb

– quack quixote – 2010-06-18T20:06:40.290

Well, I got a DVD burner + an empty DVD, I burned the ISO, tried to boot it and it is incredibly slow (takes about 5 minutes to show up the initial wizard and fails then with some strange errors). – Albert – 2010-06-18T20:10:50.397

@albert: see http://www.hak5.org/forums/index.php?showtopic=14110 for more on this issue; notice most of the configurations shown are reported not to work.

– quack quixote – 2010-06-18T20:41:24.200

Thanks for all the information. I was finally able to install it. I don't think there was really a problem in the way I booted into the setup. The problems were always some strange errors about accessing my SATA disk. After countless tries, it suddenly and randomly worked. – Albert – 2010-06-20T17:41:00.403

What would be equivalent grub2 menu-entry for ubuntu-10.10-server-i386.iso? I have a NAS with no CDROM, and attempts to install via a flash drive result in "boot error". I already have grub on the machine, so I should be able to use the same method for the installation. – dzhelil – 2011-01-08T09:42:00.547

Is it that hard to emulate a disc drive, say in GRUB? Efforts like U3Customizer take advantage of the u3 partition that some flash drives can have. And with a lot of BIOSes, those partitions are detected as USB CD-ROM drives. It would be cool to see GRUB2 as an extended bootloader to boot off of a variety of devices.

– Ehtesh Choudhury – 2012-08-29T23:56:03.577

@quackquixote: Is it possible to boot Win7 installation DVD ISO using Grub2? I cannot come up to solution as memdisk cannot load 4GB ISO image into memory, maybe loopback loop /iso/win7.dvd.iso + ntldr (loop)/bootmgr will do the job? – dma_k – 2014-05-12T10:40:05.543

1

You can use dd from the terminal to write an iso file to a partition. Just be careful, if you use dd wrong you can wipe everything. It should look something like this: dd if=Desktop/LinuxCDFile.iso of=/Path/To/Partition

Naos parth

Posted 2010-06-18T14:25:36.080

Reputation: 11

But the partition needs to be Primary in order to be bootable by Windows Loader. – Firelord – 2015-03-23T17:22:54.030

This only works occassionally, generally the result isn't bootable. – David Tonhofer – 2016-08-15T14:11:31.850

1@Firelord: Well, don’t use Windows Loader. Use Grub. Yes, it does boot Windows too, if you really need to. – Evi1M4chine – 2018-01-15T01:39:45.487