How to boot from an .iso file in GRUB2? [duplicate]
Yes, please elaborate on what you mean. This is an interesting topic; booting from an .iso file is potentially very useful.
6 Answers 6
It may be much easier than the impression you get from all the detailed explanations on the web. I just did the following on Ubuntu 12.04 to boot FreeDOS .iso for a firmware update
sudo -s apt-get install grub-imageboot mkdir /boot/images/ cp $YOUR_ISO_FILE.iso /boot/images/ update-grub2
Sometimes, you may need 2 more steps to do before running update-grub2:
If you never did it before, you need to edit /etc/default/grub so that you see the grub menu on boot:
## To show the menu, disable the hidden_timeout, and set a timeout #GRUB_HIDDEN_TIMEOUT=0 GRUB_TIMEOUT=10
For some .iso images, you may need to add this option in /etc/default/grub-imageboot : (I needed it for my FreeDOS .iso)
If you did edit one of these config. files, you need to run update-grub2 again.
Update: Here is the resulting menuentry asked by «dma_k»
menuentry "Bootable ISO Image: SV100S2_64_128_120229" < insmod part_msdos insmod ext2 set root='(hd0,msdos6)' search --no-floppy --fs-uuid --set=root 6ca082d0-63d0-48c3-9e5f-2ce5d7a74fe4 linux16 /boot/memdisk iso raw initrd16 /boot/images/SV100S2_64_128_120229.iso >
This was for a FreeDOS image with some firmware update or such.
Thanks, I see. Have you found any limitations with this approach? I have a feeling that memdisk can only load images say less then 1GB, something more heavy (e.g. Win7 DVD ISO) is causing problems.
I’m assuming you want to add a .iso entry to the GRUB menu and boot it ?
I found this info on Ubuntu Forums
Problem is (as I found out the hard way today) that it’s still impossible to install from a grub-mounted iso because the installer crashes when trying to unmount the iso. *sigh
I came across here because I got tired of burning countless bootable ISO 9660 images and thus wanted to use GRUB 2 to bootstrap a FreeDOS one for updating the firmware/microcode of Seagate HDDs. As a complement or alternative to mivk’s answer (using memdisk of syslinux), the following was what I had done to leverage the power of GRUB 2:
- Install the syslinux-common package (for using memdisk within it; grub-imageboot is a non-essential hooking package)
- Press the ‘c’ key (mnemonic for command) to activate the command prompt of GRUB 2’s builtin mini-shell (or, more precisely, the minimal BASH-like shell)
- Issue the 3 lines of commands in the GRUB 2’s mini-shell:
linux16 (hd0,gpt2)/usr/lib/syslinux/memdisk iso raw initrd16 (hd0,gpt3)/myUserAccount/download/Barracuda-ALL-GRCC4H.iso boot # where Barracuda-ALL-GRCC4H.iso is a FreeDOS-based ISO 9660 image, and # the mathematical 2-tuples or ordered pairs, (hd0,gpt2) and (hd0,gpt3), # are GRUB 2's respective device notations for my rootfs partition # (e.g., /dev/sda2) and home partition (e.g., /dev/sda3). # NOTE: This procedure also applies to Seagate's SeaTools (based on # FreeDOS as well); just substitute the file SeaToolsDOS223ALL.iso # for Barracuda-ALL-GRCC4H.iso.
By manipulating commands directly in the mini-shell, this procedure is more flexible and smipler than most of the aforesaid methods since you do not have to bother to tweak and update those GRUB 2’s configurations every time you wanna try a different Linux distro or a BSD-based live CD.
Currently, it is these 4 lines of commands that one can use as a generic pattern in the GRUB 2’s mini-shell, i.e., the loopback-linux-initrd-boot sequence plus some argument(s) passed to the given kernel, for example, to bootstrap as many popular Linux ISO images as possible (in this case is with 3 kernel commandline arguments for System Rescue CD):
loopback lb (hd0,gpt3)/myUserAccount/download/systemrescuecd-x86-3.7.0.iso linux (lb)/isolinux/rescue64 isoloop=systemrescuecd-x86-3.7.0.iso setkmap=us docache initrd (lb)/isolinux/initram.igz boot
N.B. The loopback part of the generic pattern is not, strictly speaking, mandatory for Linux, when you intend to install a Linux distro such as a Debian derivative without wasting an optical disc.
How do I boot from ISO file stored on hard disk?
I know that I can create/burn bootable CD/DVD or live USB and can boot/install from it. But suppose I am currently running GNU/Linux and I’ve ISO file of another GNU/Linux that I want to install on my hard disk, then Can I directly boot from ISO from hard disk and try/install that GNU/Linux operating system?
1 Answer 1
Yes, you can accomplish this by adding a menu entry to the GRUB boot loader menu.
You can add a custom GRUB menu entry by editing /etc/grub.d/40_custom ,
Example of custom menuentry:
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. menuentry "Trisquel ISO" < set isofile="/Operating_Systems/Trisquel_7.0_i686/trisquel_7.0_i686.iso" loopback loop (hd0,5)$isofile linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet splash initrd (loop)/casper/initrd >
Instruction & Explanation:
- The command set is used for storing the path of the ISO file into a variable, here isofile .
- loopback is used to make a device from a file system image. In order to do that, it is necessary to specify the device and image file. Here we used (hd0,5)$isofile in which (hd0,5) represents the fifth partition of the disk.
- Points to note: In (hd0,5) ,
1 st digit represents the device number which starts from 0 (here : 0 = 1 st device) and
2 nd digit represents the partition number which starts from 1 (here 5 = 5 th partition).
That means /dev/sda5 - And variable $isofile has the path of the ISO file. So, finally it becomes (hd0,5)/Operating_Systems/Trisquel_7.0_i686/trisquel_7.0_i686.iso .
- For more information, visit : How to specify devices and files.
$ 7z l trisquel_7.0_i686.iso | grep vmlinu 2014-10-29 21:41:43 . 5841680 5841680 casper/vmlinuz 2014-11-03 00:45:09 . 5844176 5844176 casper/vmlinuz.netinst
$ 7z l trisquel_7.0_i686.iso | grep initrd 2014-11-03 00:45:19 . 16851900 16851900 casper/initrd 2014-11-03 00:45:09 . 9398592 9398592 casper/initrd.netinst
After editing /etc/grub.d/40_custom , GRUB needs to be updated by update-grub2 command. Upon rebooting, you will find the custom menuentry you’ve added on the GRUB screen. And you may use the Live environment of a GNU/Linux distribution.
In order to perform installation from ISO, installer may need to unmount any mounted partitions; i.e. say another system is mounted at /isodevice , then you can umount -l /isodevice .
Install Ubuntu from ISO image directly from hard disk of a system running Linux? [duplicate]
I don’t want to burn a CD, DVD or USB memory stick. And I don’t care about saving the existing operating system (Linux Mint). I want to install Ubuntu (actually Kubuntu 12.04 LTS) to the computer directly from the ISO image. The image is for the Kubuntu Live DVD (3.5 GB). The computer is now booted into Linux Mint. A set of command line steps would be satisfactory. In my mind, I simply need to trick the existing system into thinking I inserted a CD/DVD, right? I know there is a similar question already but it does not have a good answer. The answer basically says, «see this link.» I reviewed the link and I decided that StackExchange needs a good answer to this question. Furthermore, most answers at other places on the Internet assume the user is coming to Ubuntu from Windows. So I think this question is one that needs a good answer here. Thanks
@fossfreedom — did you read the answer to that question? It isn’t really an answer — at least it does not strike me as an answer worthy of StackExchange. Surely there is a better answer out there.
2 Answers 2
I found this looking around on the net.
Grub2 is capable of directly booting ISO images for many Linux distros if the entries have been properly defined in the Grub2 configuration files.
The ISO image must be placed on a separate partition that does not have an operating system installed on it. For the sake of simplicity, we would place it inside a new directory under /boot (assuming it is on a separate partition).
- Create the new directory and copy your ISO image:
sudo mkdir /boot/iso sudo cp ~/Desktop/name.iso /boot/iso
gksudo gedit /etc/grub.d/40_custom
#!/bin/sh echo "Adding 40_custom." >&2 exec tail -n +4 $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. menuentry "Kubuntu ISO" < set isofile="/boot/iso/kubuntu-12.04.iso" loopback loop (hd0,8)$isofile linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject initrd (loop)/casper/initrd.lz >
- Kubuntu ISO = The name you want to display in the Grub menu.
- boot/iso/kubuntu-12.04.iso = The location and name of your ISO image.
- (hd0,8) = The partition which contains the ISO image.
- note: the tail -n +4 means simply «which line grub starts to read the configuration from as is». the 4th line in this example is the first comment line, which is fine.
Grub reads the partitions in a different way than Ubuntu does. ‘hd0’ means first HDD which is read as sda by Ubuntu, and 8 is the partition which is the same as for Ubuntu. So in other words, (hd0,8) means ‘sda8’.
To find out your partition, run this command in a Terminal:
Suppose your image is contained in the sda1 partition, you’d change (hd0,8) in the above line to (hd0,1) and if the image is in the sdb1 partition, you’d change (hd0,8) to (hd1,1) .
That’s all. Now you can double-click the ‘Install’ icon at the desktop and proceed with the installation.