Don't understand german? Read or subscribe to my english-only feed.

Boot an ISO via Grub2

With grub2 you can directly boot an (iso9660) ISO using its loopback option. This is great because it provides another nice rescue scenario – for example when using grml (the Debian based Linux Live-CD for sysadmins). You no longer need to extract kernel and initrd from the ISO to be able to boot it using the isofrom bootoption. All you need to do is put a plain grml ISO to your harddisk.

Due to popular request (especially in #grub) PLEASE NOTE: grub itself can NOT boot CDROM images/ISOs. Neither version 1 nor version 2 of grub. Grml provides this feature via its isofrom bootoption. Grub2 strongly simplifies this setup with its loopback option but grub alone will NOT be enough. It’s the live system (as for example grml) that has to support this “boot from ISO” feature.

I’ve tested it with grml-small 2008.11 and grml-small 2009.05-rc1 using grub2 from Debian/unstable (1.96+20090317-1). In the following example the ISO file grml-small_2008.11.iso is available in directory grml on device /dev/sda1. You can boot it from the interactive grub shell using:

loopback loop (hd0,1)/grml/grml-small_2008.11.iso
linux    (loop)/boot/grmlsmall/linux26 isofrom=/dev/sda1/grml/grml-small_2008.11.iso boot=live quiet vga=791 noeject noprompt 
initrd   (loop)/boot/grmlsmall/initrd.gz
boot

So if you are using grub2 already consider adding an entry like the following to your grub config (/boot/grub/grub.cfg):

menuentry "grml-rescue system from harddisk (ISO = grml-small_2008.11.iso)" {
  loopback loop (hd0,1)/grml/grml-small_2008.11.iso
  linux    (loop)/boot/grmlsmall/linux26 isofrom=/dev/sda1/grml/grml-small_2008.11.iso boot=live quiet vga=791 noeject noprompt 
  initrd   (loop)/boot/grmlsmall/initrd.gz
}

This entry gives you the option to boot grml from your harddisk even if you don’t have the possibility to boot via CD/USB/PXE/….

Tip: starting with grml 2009.05(-rc1) you can also use findiso=/path/to/grml.iso instead of isofrom=/dev/sdX/path/to/grml.iso. findiso is a dynamic version of isofrom as it looks for the specified ISO file on all disks where it usually looks for the .squashfs file (so you don’t have to know the device name compared to isofrom=…). The above configuration using findiso is even easier to set up and would look like this:

menuentry "grml-rescue system from harddisk (ISO = grml-small_2008.11.iso)" {
  loopback loop (hd0,1)/grml/grml-small_2008.11.iso
  linux    (loop)/boot/grmlsmall/linux26 findiso=/grml/grml-small_2008.11.iso boot=live quiet vga=791 noeject noprompt 
  initrd   (loop)/boot/grmlsmall/initrd.gz
}

13 Responses to “Boot an ISO via Grub2”

  1. Jay Says:

    Hi there,
    I’m probably the first one who read this, May 25th, 2009.
    I’v spent hours on the internet looking for a sulution to boot ISOs with GRUB.
    But I got no luck coz all the people are talking about GRUB Legacy or Grub4Dos.
    And I was wondering if GRUB2 could do some magic…and Google brought me here…It’s a really good news for me.
    Haven’t tried it, but as you have confirmed…I believe I’m gonna have the beautiful GRUB menu in a few minutes.
    Thanks mikas.

  2. Robert Smol Says:

    Hi,
    can I install grub2 on a USB stick and then load the ISO from there? That would allow me to have multiple boot CDs on a 16GB USB stick. Is this possible?

  3. mika Says:

    @Robert: I don’t see any reason why this shouldn’t work. :)

    regards,
    -mika-

  4. mirabilos Says:

    https://www.mirbsd.org/permalinks/wlog-10_e20090527-tg.htm

    Too bad we can’t do that to MirOS bsd4grml, which _is_ part of
    recent grml editions after all, yet. GNU GRUB2 cannot boot the
    kernel (nor a stock 4.4OpenBSD one, FWIW), and while the MirOS
    bootloader (ldbsd.com) is a multiboot OS kernel it doesn’t ac-
    cept a module/initrd with the kernel yet. May just hack it…

  5. mark Says:

    hi,

    I currently use GRUB 0.9 (I think) an I am using the following command to make a bootable ISO which can be burned on a CD

    mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o grub.iso iso

    I got these instructions from: http://www.gnu.org/software/grub/manual/html_node/Making-a-GRUB-bootable-CD_002dROM.html

    Now, I am really keen on using GRUB 2 instead so I can boot ISOs directly. Based on the mkisofs command above, what would be the equivilent for GRUB 2 so I can use GRUB 2 as a boot loader rather than GRUB 1?

    Just like Jay, I have been searching and surfing the entire Google and I ended up here :)

    P.S. How do I know what version of GRUB I have?

  6. mirabilos Says:

    @mark: I think you’re a little confused.

    First of, if you have /boot/grub/stage2 and stage1*, then
    you have GNU grub-legacy; if you have /boot/grub/core.img
    and *.mod, then you have GNU grub2.

    Secondly, the method Mika writes about in here is *not*
    about making an ISO bootable. It’s rather about using a
    grub2 installed on the *hard disc* to load a kernel and
    initrd image from within an ISO (it doesn’t matter if it
    is bootable or not).

    To make a bootable ISO/CD, you do things as usual. Your
    current way of doing it uses grub-legacy but is just fine.

  7. mark Says:

    Secondly, the method Mika writes about in here is *not*
    about making an ISO bootable. It’s rather about using a
    grub2 installed on the *hard disc* to load a kernel and
    initrd image from within an ISO (it doesn’t matter if it
    is bootable or not).

    Thanks for that. To be honest, that’s kind of what I wanted all this way :) So far, I currently have to extract the ISO, put it its own folder and modify the cfg file to add the folder to the path. The problem is, it doesn’t always work even if you put the right entries and it’s pointing to the right files. Depending on the distro, you will get messages relating to being unable to mount thefile system etc etc…it all varies.

    I still would like to know though, what would be the GRUB 2 equvilent to the command I have above? I want to use GRUB2. Do I replace stage2_eltorito with core.img?

  8. mirabilos Says:

    I still don’t exactly know what you’re doing, but GRUB 2 is pretty
    much undocumented.

    I can only suggest to look at /usr/bin/grub_mkrescue, which creates
    an El Torito image by doing a 「cat cdboot.img core.img >grub_eltorito」

    Be sure to include biosdisk and cd9660 modules in core.img and the
    other *.mod on the CD in /boot/grub though.

    (Of course, we also have a way to boot grub2 from the MirOS first
    stage bootloader… not just via HD/USB, but also via El Torito…
    but that’d be another topic.)

  9. mark Says:

    Yep, exactly, I will see if your suggestion works. Basically what I need is an El Torito image for GRUB 2.

    The following command:


    mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o grub.iso iso

    will create the current GRUB1 boot loader on the CD (when the ISO is burned) so when the CD starts, GRUB launches and menu.lst is displayed.

    So I what I need is something like this instead:


    mkisofs -R -b boot/grub/stage2_eltorito_for_GRUB2 -no-emul-boot -boot-load-size 4 -boot-info-table -o grub.iso iso

    so when the ISO is burned GRUB2 loads. All I want to is to use GRUB2 as a boot loader on my CD instead of GRUB1 or isolinux.

    Just for the record, this is my command if I want to use isolinux as a boot loder but I want to use GRUB2 instead.


    mkisofs -o livecd.iso -r -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -V livecd -no-emul-boot -boot-load-size 4 -boot-info-table .

  10. Mart Says:

    I haven’t tried grub2 yet, but what I would like to be able to do is easily boot a .iso file WITHOUT examining its content and finding the kernel and specifying, just like when you put a CD in your CD drive.

    So with grub2, is it possible to do something like:


    loopback loop (hd0,0)/myfolder/mycd.iso
    chainloader (loop)

    So that it would do the same thing as if booted from the CD? Because I’ve been trying to do this with grub4dos that can boot from .iso, but whenever I try to boot from a Linux distro .iso, it doesn’t work because it can’t find the data on the CD or something…

  11. mirabilos Says:

    Hi again.

    First off, you generate the appropriate El Torito boot
    image for GNU GRUB2 by something like this:

    $ grub-mkimage -o core.img biosdisk iso9660
    $ cat /usr/lib/grub/i386-pc/cdboot.img core.img >torito.img

    Then you can use -b torito.img with the same options you’re
    using otherwise (do *not* forget -no-emul-boot
    -boot-load-size 4 -boot-info-table), it doesn’t even need
    to reside in the filesystem itself, as mkisofs will include
    it in the appropriate place itself. (The core.img may,
    however, reside at /boot/grub/ in the filesystem.)

    You *must* include several other files in the filesystem
    though:

    $ cd /usr/lib/grub; for a in *.mod efiemu??.o command.lst \
    moddep.lst fs.lst handler.lst parttool.lst; do
    test -e $a && cp $a ~/cddir/boot/grub/
    done

    The other thing you ask for, loopback chaining, is not
    possible, because grub’s loopback code will not be ac-
    cessible from within the chained-to bootloader. Sorry.
    You could achieve something similar with MEMDISK, but
    only for relatively small images.

  12. AndrewBoldman Says:

    Hi, cool post. I have been wondering about this topic,so thanks for writing.

  13. Kim Says:

    Great article!

    But how to get Grub2 on a media eg. USB-Stick in first place?