How to boot on an ISO image from Grub

If you need to use multiple Linux distributions, you do not have so many options. You can either install it, on your machine or in a virtual one, or you can boot on it from an ISO file in live mode. The second option, if less needy in hard drive space, is bothersome as you will need a USB stick or CD to hold the ISO file and boot from. However, there is a third alternative which is a bit of a compromise: have the ISO image on your hard drive, and boot into it in live mode at startup. Less needy in disk space than a full install, and fully functional, this seems to be a good alternative to a slow virtual machine. I will explain how to do this using the popular bootloader Grub.

What do you need?

Obviously you will need to be using Grub, which is the case on pretty much all modern Linux distributions. You will also need to have an ISO file of the distribution of your choice, downloaded on your hard drive. Finally, you should know where your boot partition is, and how to express it in Grub language. For this, launch:

# fdisk -l

and the boot partition is the one with the '*'. For me it's /dev/sda1, which is written (hd0,1) in Grub language.

For reference, sda2 would be (hd0,2), sdb1 would be (hd1,1), etc. (You got the point).

What do we edit?

First, open /etc/default/grub and check that the following line:

#GRUB_HIDDEN_TIMEOUT=0

is indeed commented with a '#' in front.

Save it and then go open /etc/grub.d/40_custom.

This file will be where you put the arguments to boot on an ISO. The structure is of the form:

menuentry "[Entry's title in the grub screen]" { 
set isofile="[path to ISO file]" 
loopback loop [boot partition in Grub language]$isofile 
[some specific] arguments
}

For example, if you wish to boot Ubuntu from an ISO file, you want to append this to your 40_custom file:

menuentry "Ubuntu 14.04 (LTS) Live Desktop amd64" { 
set isofile="/boot/ubuntu-14.04-desktop-amd64.iso" 
loopback loop (hd0,1)$isofile 
linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=${isofile} quiet splash 
initrd (loop)/casper/initrd.lz 
}

If you would like to launch Gparted instead:

menuentry "GParted Live amd64" { 
set isofile="/boot/gparted-live-0.18.0-2-amd64.iso" 
loopback loop (hd0,1)$isofile 
loopback loop $isofile 
linux (loop)/live/vmlinuz boot=live config union=aufs noswap noprompt ip=frommedia toram=filesystem.squashfs findiso=${isofile} 
initrd (loop)/live/initrd.img 
}

Or even Fedora:

menuentry "Fedora 20 Live Desktop x86_64" { 
set isofile="/boot/Fedora-Live-Desktop-x86_64-20-1.iso" 
loopback loop (hd0,1)$isofile 
loopback loop $isofile 
linux (loop)/isolinux/vmlinuz0 root=live:CDLABEL=Fedora-Live-Desktop-x86_64-20-1 rootfstype=auto ro rd.live.image quiet rhgb rd.luks=0 rd.md=0 rd.dm=0 iso-scan/filename=${isofile} 
initrd (loop)/isolinux/initrd0.img 
}

Note that the arguments will change depending on the distribution. Hopefully, there are a few places where you can start looking. I like this one, but there are plenty of others. Also, take into consideration where you place your ISO files. If your home directory is encrypted or out of reach, you might prefer placing the files in your boot partition like in the example. But make sure that you have enough room first.

Finally, don't forget to save 40_custom and update grub with:

# sudo update-grub

to see your changes appear at the next boot.

What next?

Want more? Well by playing a bit with the arguments, you can boot on an ISO and have it do something instantly. For example, if you are completely paranoid and wish to have an option to erase your hard drive quickly, it is possible to set up something using DBAN. Now be really careful as this will wipe your disk without recovery option on startup:

menuentry "Darik's Boot and Nuke" { 
set isofile="/boot/dban.iso" 
loopback loop (hd0,1)$isofile 
linux (loop)/dban.bzi nuke="dwipe" silent 
}

Alternatively,

menuentry "Darik's Boot and Nuke" { 
set isofile="/boot/dban.iso" 
loopback loop (hd0,1)$isofile 
linux (loop)/dban.bzi 
}

will show you the DBAN's options and let you choose to wipe your drive. Be careful as it is still very dangerous.

To conclude, there are plenty of things to do with ISO files and Grub: whether you want a quick live session or prefer to destroy everything with the tip of your finger. The next step would be to launch some privacy focused distribution like Tails for example.

What do you think of booting on an ISO from Grub? Is it something you would consider doing? And why? Let us know in the comments.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.


Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.

Adrien Brochard

I am a Linux aficionado from France. After trying multiple distributions, I finally settled for Archlinux. But I am always trying to improve my system by stacking up tips and tricks.

Latest posts by Adrien Brochard (see all)

7 thoughts on “How to boot on an ISO image from Grub

  1. Does it work for macosx computers ?? :)

    I got two macs. They do not support boot from USB-stick or DVDs.

    macs uses EFI-Fork not Bios on startup.

  2. @Adrien, nice tutorial. The one thing that remains to be fully explained is the source for the boot argument(s)...where do you find that information for any given distro?

    I believe the above method is pretty specific to the Linux OS but could be accomplished with a dual boot system that uses Grub as a bootloader.

  3. I setup Grub to boot from an ISO using these much easier steps.

    Install grub-imageboot
    copy your .iso file(s) to /boot/images/
    run update-grub2

  4. Seems like an easy way to boot an ISO but I am having a problem using it with Mint 17 xfce. Grub shows the iso I want to boot but just reboots the laptop rather than the iso. I tried putting the iso in /home/don/Downloads and in /boot/ same result, just reboots.

  5. Are the fourth lines from the two entries below in the article correct, or are they a line duplication error? The other entries only have one loopback line.

    If you would like to launch Gparted instead:

    1 menuentry "GParted Live amd64" {
    2 set isofile="/boot/gparted-live-0.18.0-2-amd64.iso"
    3 loopback loop (hd0,1)$isofile
    4 loopback loop $isofile
    5 linux (loop)/live/vmlinuz boot=live config union=aufs noswap noprompt ip=frommedia toram=filesystem.squashfs findiso=${isofile}
    6 initrd (loop)/live/initrd.img
    7 }

    Or even Fedora:

    1 menuentry "Fedora 20 Live Desktop x86_64" {
    2 set isofile="/boot/Fedora-Live-Desktop-x86_64-20-1.iso"
    3 loopback loop (hd0,1)$isofile
    4 loopback loop $isofile
    5 linux (loop)/isolinux/vmlinuz0 root=live:CDLABEL=Fedora-Live-Desktop-x86_64-20-1 rootfstype=auto ro rd.live.image quiet rhgb rd.luks=0 rd.md=0 rd.dm=0 iso-scan/filename=${isofile}
    6 initrd (loop)/isolinux/initrd0.img
    7 }

Leave a comment

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