Booting ISO or USB key images directly from Grub2?

May 25th, 2010 by lucas

I’m playing with the idea of booting ISO images and USB key images stored in a disk partition directly from Grub2. That would allow to install Linux or test liveCDs without even using a USB key. It seems that Grub2 has everything needed for that (with a combination of drivemap and chainloader), but I can’t seem to get it working and, as usual with boot stuff, it’s a pain to understand what’s happening.

Has somebody recently tried that, or can point me to a howto?

23 Responses to “Booting ISO or USB key images directly from Grub2?”

  1. Brian wrote on 05/25/10 at 7:01 pm :

    Will be watching these comments closely for a solution! Thats an exciting prospect!

  2. derande wrote on 05/25/10 at 7:10 pm :

    I, too, have wanted to accomplish this but lack the Grub2 knowledge to do so. Very exciting indeed!

  3. iria wrote on 05/25/10 at 7:11 pm :

    Maybe this

    http://manual.sidux.com/en/hd-install-opts-en.htm#grub2-fromiso

  4. YoBoY wrote on 05/25/10 at 7:14 pm :

    Have you tried like explained in our french doc
    http://doc.ubuntu-fr.org/tutoriel/grub2_lancer_des_images_iso

    If this isn’t working let me know :)

  5. Colin Watson wrote on 05/25/10 at 7:20 pm :

    drivemap and chainloader won’t work; remember that the kernel and initrd you boot have to start out from bare metal and find their root filesystem, and as such you need active cooperation from them (they might offer some magic boot parameter you can pass to tell them to loop-mount an ISO). After that you want something like ‘loopback loop0 /path/to/iso’.

    Ideally you would then be able to ‘set root=(loop0)’ and just forget about the loopback bit for the rest of grub.cfg, but we need to get http://bazaar.launchpad.net/~ubuntu-core-dev/ubuntu/maverick/grub2/maverick/annotate/head:/debian/patches/956_loopback_root.diff merged in order for that to work properly. In the meantime, you should just be able to prefix the kernel and initrd paths with (loop0) in order to get GRUB to read them from the loopback filesystem.

  6. anonymous wrote on 05/25/10 at 7:23 pm :

    I’ve been able to boot the Lucid Desktop and Netboot ISOs from my USB flash drive with the following grub.cfg stanzas:

    menuentry “Ubuntu 10.04 Lucid Lynx Desktop AMD64″ {
    loopback loop /images/ubuntu/ubuntu-10.04-desktop-amd64.iso
    set root=(hd0,1)
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/images/ubuntu/ubuntu-10.04-desktop-amd64.iso noeject noprompt
    initrd (loop)/casper/initrd.lz
    }

    menuentry “Ubuntu 10.04 Lucid Lynx Desktop i386″ {
    loopback loop /images/ubuntu/ubuntu-10.04-desktop-i386.iso
    set root=(hd0,1)
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/images/ubuntu/ubuntu-10.04-desktop-i386.iso noeject noprompt
    initrd (loop)/casper/initrd.lz
    }

    menuentry “Ubuntu 10.04 Lucid Lynx Netbook i386″ {
    loopback loop /images/ubuntu/ubuntu-10.04-desktop-i386.iso
    set root=(hd0,1)
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/images/ubuntu/ubuntu-10.04-netbook-i386.iso noeject noprompt
    initrd (loop)/casper/initrd.lz

    }

    These didn’t work when I tested them in KVM, but they did work on real hardware, so be wary.

  7. TGM wrote on 05/25/10 at 7:29 pm :

    As above (anonymous) but I have:

    menuentry “Kubuntu 10.04 x64″ {
    loopback loop /iso/kubuntu-10.04-desktop-amd64.iso
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/iso/kubuntu-10.04-desktop-amd64.iso noeject noprompt –
    initrd (loop)/casper/initrd.lz
    }

    menuentry “Kubuntu 10.04 x64 (XBMC)” {
    loopback loop /iso/kubuntu-10.04-desktop-amd64-xbmc.iso
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/iso/kubuntu-10.04-desktop-amd64.iso noeject noprompt –
    initrd (loop)/casper/initrd.lz
    }

    my iso folder is on the root of the drive, next to the grub dir.

  8. Anonymous wrote on 05/25/10 at 7:40 pm :

    Many, many people want this. As pointed out above, you can do it in some special cases like Linux installer ISOs, but only because those installers use kernels and initrds that understand ISOs. If grub2 had hard-disk emulation support (such as that in the grub4dos fork of grub1), it could handle disks that just use a CD to boot like a floppy.

    However, if you wanted to handle it in the general case for arbitrary bootable ISOs, you would have to have GRUB leave part of itself around when the OS runs much like it does with drivemap, but instead of a simple interrupt hook, it would need to emulate a full CD-ROM drive and controller (ATAPI, SCSI, SATA…) in a way that arbitrary OSes could understand. Not likely to happen.

  9. Rob wrote on 05/25/10 at 8:00 pm :

    Try PLoP (http://www.plop.at). It’s an alternative boot manager on its own that can boot off of USB sticks and other devices, but you can add it as an option in Grub, and use that to boot a USB device if Grub on its own cannot.

  10. Nice Business Crm Solutions photos | Selkblog.com - Best Quality Original Articles, images, videos For Massive Exposure. wrote on 05/25/10 at 8:49 pm :

    [...] Lucas Nussbaum's Blog » Blog Archive » Booting ISO or USB key … [...]

  11. Olezfdtd wrote on 05/25/10 at 10:24 pm :

    I haven’t done this with grub 2, but grub4dos can do it.
    Here’s a (rather sec) tutorial:
    http://olezfdtd.wordpress.com/2010/02/26/boot-iso-files-from-usb-with-grub4dos/

    Keep in mind that not all iso’s can be booted this way, but a large amount can.

  12. slh wrote on 05/25/10 at 10:25 pm :

    Like Colin Watson already mentioned, to chainload an ISO from grub2 is unfortunately not possible (yet/ ever?), as it would require grub2 to intercept not only BIOS calls for emulating a CD drive from the given ISO (so the embedded ElTorio bootloader can take over), but also to fool higher level driver OS drivers. While kernel and initramfs can be loaded through grub2′s loopback option, grub.cfg still needs to know about their exact location inside the ISO. Additionally the initramfs must be able to find the root device itself, which unfortunately rules out generic solutions and makes it not only dependent on proper OS/ initramfs support, but also highly distribution specific.

    For sidux, we have solved this through the custom grub2-fll-fromiso package mentioned by iria.
    Vcs-Svn: svn://svn.berlios.de/fullstory/grub2-fll-fromiso/trunk
    Vcs-Browser: http://svn.berlios.de/svnroot/repos/fullstory/grub2-fll-fromiso/trunk/
    This package plugs into update-grub (Debian specific), searches for ISOs matching a given regexp below the configured directories and then looks inside the ISOs (through genisoimage’s isoinfo, to avoid having to mount it) for kernel and initramfs files, matching a hardcoded regexp (vmlinuz, initrd.img) for the file names. Once these are known, an appropriate stanza can be written to grub.cfg (the example is slightly more complex than necessary, given that the ISOs are stored on LVM2):

    ### BEGIN /etc/grub.d/60_fll-fromiso ###
    menuentry "sidux-2009-04-moros-kde-lite-amd64-200912310312 (vmlinuz0.amd)" {
    insmod iso9660
    insmod lvm
    insmod ext2
    set root='(vg-challenger-pyfll)'
    search --no-floppy --fs-uuid --set 5050dfe1-96ac-4680-a093-6fdef64c5c56
    loopback loop /sidux-2009-04-moros-kde-lite-amd64-200912310312.iso
    linux (loop)/boot/vmlinuz0.amd fromhd=/dev/mapper/vg--challenger-pyfll fromiso=/sidux-2009-04-moros-kde-lite-amd64-200912310312.iso boot=fll lang=de_DE TZ=Europe/Berlin quiet noeject hostname=challenger username=slh
    initrd (loop)/boot/initrd0.amd
    }
    ### END /etc/grub.d/60_fll-fromiso ###

    The drawback, besides having to call update-grub for updating grub.cfg, is, that this needs a lot of cooperation from the affected live ISOs and exact knowledge about distribution specific boot parameters. In case of sidux, these are fromhd= (the block device which holds the ISO), fromiso= (path to the ISO, relative to the afforementioned block device) and boot=fll, which calls the live-sidux specific initramfs scripts to locate root device and evaluate boot parameters. lang=, TZ=, hostname=, username= and the default quiet and noeject parameters are optional and configurable.

    While this works reliably for sidux and could be enhanced to cover additional distributions providing similar functionality, it still depends on a lot of cooperation from the live ISO and its initramfs implementation – in addition to a positive distribution recognition. Unfortunately these boot parameters for finding the root device from non-ElTorito block devices vary greatly between live distributions, if they’re implemented in the given distribution at all.

  13. Jordan wrote on 05/25/10 at 11:54 pm :

    @slh
    You may want to consider adding a loopback.cfg for sidux to make loop booting easier:
    http://www.supergrubdisk.org/wiki/Loopback.cfg

    @cjwatson
    “set root=loop0″ works fine with vanilla grub 1.98, in fact using a loopback.cfg depends on this.

  14. Faidon Liambotis wrote on 05/26/10 at 12:05 am :

    What about memdisk from syslinux[1]?

    I’ve done this before with grub1, and it worked perfectly. Haven’t done it with grub2 but the wiki page mentions it, along with a configuration excerpt, so it should work.

    [1]: http://syslinux.zytor.com/wiki/index.php/MEMDISK

  15. Faidon Liambotis wrote on 05/26/10 at 12:50 am :

    Ah, booting *Linux* installers or liveCDs; well, memdisk won’t work for that, obviously. I’ve successfully used it to boot vendor foo (hard disk diagnostics etc.) which are silly enough to work.

  16. Robert Estes Kennington | Selkblog.com - Best Quality Original Articles, images, videos For Massive Exposure. wrote on 05/26/10 at 3:48 am :

    [...] Lucas Nussbaum's Blog » Blog Archive » Booting ISO or USB key … [...]

  17. Fabian wrote on 05/26/10 at 9:05 am :

    I’ve run into the same problem when I wanted to integrate the Balder FreeDOS disk image into my GRUB2 boot menu, see #564509. I’ve got it to work using the memdisk image from syslinux-common: You load it as a kernel and pass the actual image as an initrd. Please find working packages here:
    http://debian.greffrath.com/unstable/balder_10-0fab1.dsc

  18. Apple USB Power Adapter for iPod/iPhone - iPhone Maker wrote on 05/26/10 at 6:53 pm :

    [...] Lucas Nussbaum's Blog » Blog Archive » Booting ISO or USB key … [...]

  19. teethman wrote on 06/2/10 at 9:53 am :

    Thanks very helpful. I’ve been looking for this. God bless!!!

  20. Grub2 boot from .img wrote on 12/4/10 at 11:44 pm :

    [...] of your partition (C-ROOT, find it through gparted or some other tool) This might interest you: http://www.lucas-nussbaum.net/blog/?p=485 Good luck, ask away if you need to, I'll help as much as I [...]

  21. mate86 wrote on 01/2/11 at 5:58 am :

    I

  22. morzakk48 wrote on 01/2/11 at 12:05 pm :

    I

  23. inhectenevy wrote on 08/8/11 at 11:58 pm :

    Hiya , searching for the best possible nearly insightful penny stock news letter? .
    I RECENTLY have definitely one you need to check out I try and give the best and brisk data, thus if financial firms of involvement to you personally delight check out my penny stock newsletter.