Boot a Mint .iso From Your Hard Drive Using Grub2 - with no DVD or USB

austintexas
  8 years ago
  6

How To Boot a Mint .iso From Your Hard Drive Using Grub2 - with no DVD or USB

The Simple Version:

You must have a working linux OS using Grub 2.

Move (or copy) your .iso file from your Downloads directory into the /boot directory.

sudo mv ~/Downloads/linuxmint-17-mate-dvd-32bit.iso /boot/
(- edit for the correct source directory and .iso file name)

Open /boot/grub/grub.cfg as root, in your text editor. (Mine is gedit.)
gksudo gedit /boot/grub/grub.cfg
For KDE the command is:
kdesudo kate /boot/grub/grub.cfg

Go to the bottom of the file, where you see:
### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

Change that so that it reads:
### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "Mint 17 Mate 32bit iso - this is just a title. Edit as you wish." {
set isofile="/boot/linuxmint-17-mate-dvd-32bit.iso"
loopback loop (hd0,1)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject toram
initrd (loop)/casper/initrd.lz
}
### END /etc/grub.d/40_custom ###

Edit the parts in red for the correct .iso file name.
Save the file.
Reboot and choose your new menuentry in the Grub menu. It will boot the .iso just like booting a DVD.


TIPS:
You can add more menuentries to boot as many .iso files as you want.
More examples of menuentries are here - http://community.linuxmint.com/tutorial/view/1846

The toram option in the example will load the entire .iso into ram. If you don't have at least 1.5GB ram, remove the toram option.
It takes time to load into ram, but after it is loaded it is FAST - much faster than a DVD or USB.
There is a significant difference between loading the Mint .iso into ram, and running it from the hard drive. Without the toram option, you cannot install Mint to the partition you booted from, because it cannot be unmounted. When you start the installation program, you will get a popup telling you that you have mounted partitions, and asking if you want to unmount them. You have to chose NO. If you chose YES, the installer will close immediately. You are running your operating system (the Mint iso) from a mounted partition, and it cannot run if you try to unmount that partition. You are limited to installing to some other partition or hard drive or USB drive. 

An alternative, if you still have trouble with the installation program complaining about mounted partitions, or that it cannot write a new partition table, is to run the command: sudo umount -l -r -f /isodevice

That limitation does not exist when you use the toram option. When you load your operating system into ram, you can unmount the / partition where the .iso file is. That allows you to install Mint to the partition that you booted from, or delete the partition if you want to reconfigure your partitions. Since everything is in ram, you don't need anything that is on the hard drive. 

Deleting your operating system on the hard drive and relying on the operating system that you have loaded into ram is rather like swinging on a trapeze with no net. It is not for the faint of heart. Beware of power outages or black cats walking across the keyboard. There may be rare cases where someone needs that technique.

If you have the Grub Customizer program, you can create a custom Grub menuentry with that program, also.

WARNING: Editing the /boot/grub/grub.cfg file as in the "Simple Version" example above will only create a temporary Grub menuentry. That is great for a one-time boot of an .iso file. However, when you update Grub with "sudo update-grub", the temporary entry that you created will vanish. "sudo update-grub" rebuilds /boot/grub/grub.cfg
If you want your menuentry to be persistent, you have to enter the menuentry in /etc/grub.d/40_custom
Open the text file /etc/grub.d/40_custom in your text editor, as root.
gksudo gedit /etc/grub.d/40_custom
When you open it, it will look like this:
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.

Just add your menuentry:
menuentry "Mint 17 Mate 32bit iso - this is just a title. Edit as you wish." {
set isofile="/boot/linuxmint-17-mate-dvd-32bit.iso"
loopback loop (hd0,1)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject toram
initrd (loop)/casper/initrd.lz
}
(You already know how to edit those lines for your iso.)
Save the file, and update Grub:
sudo update-grub
If you enter the menuentry in /etc/grub.d/40_custom you do not have to edit /boot/grub/grub.cfg  - the "sudo update-grub" does that for you.

Booting from the Grub prompt, without a Menuentry:
Although Grub2 must be installed and working, it is not required to have a menuentry in order to boot the ISO. Occasionally, you may have an operating system that will not boot correctly, but does give you the Grub menu.
When you see the Grub menu while booting, you can press "c" (for "command line"), and type in each command in the menuentry example at the Grub prompt (except the menuentry title line - don't enter that line).
First line:
set isofile=/boot/linuxmint-17-mate-dvd-32bit.iso
The "quote marks" are not needed here.
TIP: To make sure that you are entering the correct path, enter the first part of the line - set isofile=/boot/linu - and then press the TAB key for auto-completion of the filename. (Also, doing that means less typing! TAB completion does not always work - YMMV.)
Second line:
loopback loop (hd0,1)$isofile
For some reason, Grub2 will use that line as it is when it is part of grub.cfg. However, when using it at the grub command line, it has to be changed to (hd0,msdos1)
Remarkably, I have to use (hd0,msdos1) even when my .iso file is on sdb1. I don't understand that. It should be (hd1,msdos1) - but that does not work. Maybe it is because I have sdb set first in the BIOS boot sequence.
The line that works for me is:
loopback loop (hd0,msdos1)$isofile
Third line (remains the same):
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject toram
"toram"  is optional.
Forth line (remains the same):
initrd (loop)/casper/initrd.lz
Fifth line:
boot

The .iso file does not have to be on the hard drive, it can be on a USB drive.
You can copy it to the USB without putting it in a specific folder, or you can create a folder like /boot or /boot-isos for it.
At the Grub prompt enter the command ls to see a list of your partitions. I have 2 internal drives, so my USB drive shows as /dev/sdc, or (hd2,msdos1) in Grub2 language.   You can also use the ls command to list the files on the flash drive: ls (hd2,msdos1)/ or ls (hd2,msdos1)/iso-files

These lines work to boot the .iso from my USB, in the /boot-isos folder:
set isofile=/boot-isos/linuxmint-17-mate-dvd-32bit.iso
loopback loop (hd2,msdos1)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject toram
initrd (loop)/casper/initrd.lz
boot


This tutorial covers LEGACY/BIOS/msdos Grub2.  It may require different steps for UEFI/GPT Grub installations. Booting from a USB will work for both.

This method works for .isos such as Ubuntu, Linux Mint, LMDE, PCLinuxOS, Knoppix, Puppy Linux, Pinguy, Bodhi, Zorin, Gparted Live, Grub Rescue Remix, SystemRescueCD, and more. It may not work for some other distros, depending on how their .iso files are structured.

 en Español

Comments
jahid_0903014 9 years ago

I promoted this tutorial and I totally forgot about it. This is really useful...


ben2talk 9 years ago

A very nice tutorial. However, the main reason I like USB install is that I can install software I want for recovery or standby OS in the event of some failure. Recently I was running from USB for 3 days whilst I copied/restored/reinstalled/reformatted disks.

USB boot also removes the problem of Hard disks unmounting, but adds the bonus of

1. installing apt-fast to speed it up,

2. updating rather than being stuck with an outdated ISO

3. You can install Testdisk and whatever other software you rely on in a crisis.

4. You can install a nice dark theme if you don't like the super bright shiny Mint default.


MagicMint 9 years ago

I prefer these menu entries to be in /boot/grub/custom.cfg — they don’t interfere there with Grub’s other configuration — where the entry for LMDE 2 Betsy e.g. (which is very different from the casper-based ones!) reads:

cat << EOF
menuentry "LMDE 2 “Betsy” Cinnamon (64-bit ISO)" {
set isofile="…/lmde-2-201503-cinnamon-64bit.iso"
loopback loop (hd…,msdos…)$isofile
linux (loop)/live/vmlinuz boot=live live-config fromiso=/dev/disk/by-label/…/$isofile toram=filesystem.squashfs noprompt quiet
initrd (loop)/live/initrd.lz
}
EOF

The real form of the ellipses (…) depend on the disk configuration, of course ;-)


MagicMint 9 years ago

What’s the point of all this pain to manipulate the boot menu just for using the ISO once as an _installation_ medium from the RAM? What if something goes wrong during the installation process and you don’t have a live medium at hand?

I would understand if you’d recommend it for testing purposes or everyday use — but then, in the latter case, the ISO would be an OS which isn’t customizable :-(


MagicMint 9 years ago

@bkjaya1952: The method depicted above is a much faster way, precisely because it does _not_ need virtualization. On the other hand, I used once to start virtual machines directly from the boot menu, but this required intervention from the init system. Nowadays, I prefer _not_ to restart the system as long as possible, unless in case of absolute necessity.


topper 10 years ago

It works well (Linux Mint 17 xfce 32bit)