Use GRUB2 to Boot ISOs off a Flash Drive

Use GRUB2 to Boot ISOs off a Flash Drive

I will soon need to build a few new PCs that do not have optical drives (one will be a firewall, for example). They do not need the drives for day-to-day usage but I do need to get an OS on them. Since virtually all consumer boards now have USB and I have piles of unused flash drives laying around I decided not to spend the money on an external drive and go the flash drive route.

Here are the steps I took to get my Linux ISOs to boot off a USB flash drive. For these exact steps to work you will need an existing Linux installation (a LiveCD will work just fine).

  1. Create a new, formatted partition big enough to store your ISOs. I am using EXT4 but any filesystem supported by GRUB2 will work. I prefer to use GParted for this.
  2. Mount your new partition. Most Linux desktop distributions will do this automatically for you if you just unplug the device and plug it back in.
  3. Install GRUB2: grub-install --force --no-floppy --root-directory=[path partition was mounted] /dev/sdX where X is the flash drive.
  4. Copy over any ISOs you want to be able to boot to the root of your new partition.
  5. Create [path partition was mounted]/boot/grub/grub.cfg and add the lines

    set timeout=5
    set default=0

  6. In [path partition was mounted]/boot/grub/grub.cfg add any of the following example entries for your favorite distributions:

    menuentry "Ubuntu 10.10 Desktop i386" {
    loopback loop /ubuntu-10.10-desktop-i386.iso
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/ubuntu-10.10-desktop-i386.iso noeject noprompt splash --
    initrd (loop)/casper/initrd.lz
    }

    menuentry "Ubuntu 10.10 Server i386" {
    loopback loop /ubuntu-10.10-server-i386.iso
    linux (loop)/install/vmlinuz boot=casper iso-scan/filename=/ubuntu-10.10-server-i386.iso noeject noprompt splash --
    initrd (loop)/install/initrd.gz
    }

    menuentry "Darik's Boot And Nuke" {
    loopback loop /dban-2.2.6_i586.iso
    linux (loop)/DBAN.BZI nuke="dwipe" iso-scan/filename=/dban-2.2.6_i586.iso silent --
    }

    menuentry "Memtest 86+" {
    linux16 /memtest86+.bin
    }

I could not, for the life of me, get any Windows ISOs to boot using GRUB2. On top of that I came across a number of people trying to do the same thing whom all failed. If anyone gets this working please post in the comments. I may be able to chainload into another boot loader but that is for another day.

Update 2011.02.18
I found this. It may be nothing but it also may be a jumping off point from which to boot from a Windows ISO.

[Source]

3 thoughts on “Use GRUB2 to Boot ISOs off a Flash Drive

  1. Nick, you are a scholar and a gent. Thank you so much for posting the syntax for the Ubuntu Server ISOs. I’ve been struggling with this all day.

    Cheers,
    Tris

  2. Windows 7 install can boot off a usb drive, if you use grub, and make the first partition 5+ GB NTFS with the entire windows DVD on it.

    title Windows 7 SP1 Install
    makeactive (hd0,0)
    find –set-root –ignore-floppies /bootmgr
    chainloader /bootmgr
    boot

  3. I’ve installed XP and 2003 Server from iso files using the firadisk driver. My USB has GRUB2 as main loader for Linux iso booting, and chaining grub4dos it can be made possible.

    I’ve actually booted an 2008 server (not R2) from an iso, but have yet to install it successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *