Run ISO Files from HDD with GRUB2
Yes, you can boot and run ISO files directly from your hard drive using GRUB2, without burning them to a USB or CD. This guide explains how to set up GRUB2 to boot ISO files, covering the necessary configuration, common pitfalls, and practical tips.
Background: Why Boot from ISO on HDD?
Booting an ISO from your hard drive is useful for trying out Linux distributions, running rescue tools, or installing an OS without creating a bootable USB stick. It saves time and media, and it’s especially handy on systems where USB booting is restricted or unreliable. GRUB2, the default bootloader for most Linux distributions, can load ISO files directly if they are designed to support this method (often called “ISO boot” or “loopback boot”).
How GRUB2 Booting Works
GRUB2 uses the loopback command to mount an ISO file as a virtual device, then loads the kernel and initrd from inside that ISO. The process involves three main steps: locating the ISO, setting up the loopback device, and booting the kernel with appropriate parameters. The exact commands vary depending on the distribution, but the general structure is:
loopback loop (hd0,msdos1)/path/to/file.iso— mounts the ISO.linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/path/to/file.iso— loads the kernel (example for Ubuntu).initrd (loop)/casper/initrd.img— loads the initrd.boot— starts the system.
For distributions that support direct ISO boot, the kernel and initrd are usually located in a casper, live, or install directory inside the ISO. The exact paths and parameters are typically documented on the distribution’s wiki or in the ISO’s README.
How to Set Up GRUB2 to Boot an ISO
To add an ISO boot entry to your GRUB2 menu, you need to edit the custom configuration file /etc/grub.d/40_custom or create a new file in /etc/grub.d/. Here’s a step-by-step approach:
- Place your ISO file in a location GRUB can read, such as
/boot/iso/or a partition on your hard drive. - Open a terminal and edit
/etc/grub.d/40_customwith root privileges. - Add a menu entry like the one below, adjusting the paths and parameters for your specific ISO.
- Run
sudo update-grubto regenerate the GRUB configuration. - Reboot and select the new entry from the GRUB menu.
Example entry for a generic Linux ISO:
menuentry "My ISO" {
set isofile="/boot/iso/example.iso"
loopback loop $isofile
linux (loop)/live/vmlinuz boot=live iso-scan/filename=$isofile
initrd (loop)/live/initrd.img
}
Note that the kernel and initrd paths may differ. For Debian-based live ISOs, they are often under /live; for Ubuntu, under /casper.
Choosing the Right ISO and Parameters
Not all ISOs are designed to be booted via GRUB2’s loopback. Some distributions provide specific instructions for “ISO boot” or “netboot” but not all. The most reliable way is to check the distribution’s official documentation. For example, Ubuntu, Debian, Fedora, and Arch Linux have documented methods. When in doubt, look for a file named isolinux.cfg or grub.cfg inside the ISO to find the exact kernel parameters used for live booting.
Common kernel parameters include:
boot=casper(Ubuntu/Debian live)live-media=removable(Debian)rd.live.image(Fedora)archisolabel=ARCH_YYYYMM(Arch Linux)
These parameters tell the initrd where to find the live filesystem. Using the wrong ones will result in a boot failure or a kernel panic.
Common Problems and Solutions
Booting ISOs via GRUB2 can be finicky. Here are frequent issues and how to resolve them:
- Error: file not found — Check the path to the ISO. GRUB uses its own device naming (e.g.,
(hd0,msdos1)). Use thelscommand in the GRUB shell to find the correct partition. - Kernel panic — Usually means the kernel parameters are wrong. Verify the paths inside the ISO and the correct
iso-scan/filenameparameter. - No loopback support — Ensure your GRUB2 version includes the
loopbackmodule. Most modern distributions have it built-in. - ISO not found after update-grub — If you placed the ISO on a partition that is not mounted at boot, GRUB may not see it. Put it in
/bootor ensure the partition is accessible.
If you encounter issues, boot into the GRUB command line (press c at the menu) and manually type the commands to debug.
Comparison: HDD ISO Boot vs USB vs Optical Disc
Booting from an ISO on the hard drive has advantages and disadvantages compared to other methods:
- HDD ISO boot: No extra media needed, fast (limited by disk speed), but requires GRUB2 configuration and may not work with all ISOs.
- USB boot: Highly portable, works on most systems, but requires creating a bootable USB (which can be time-consuming) and may be blocked on some secure-boot systems.
- Optical disc: Universally compatible, but slower and requires blank discs.
For a one-off test or install, HDD ISO boot is convenient. For repeated use across multiple machines, a USB stick is often better.
Safety and Limitations
Booting an ISO from your hard drive is generally safe, but there are a few things to keep in mind:
- Make sure you have a backup of your GRUB configuration before editing. A mistake can leave your system unbootable, but you can usually recover with a live USB.
- Some ISOs, especially older ones, may not support loopback booting. Check the distribution’s documentation.
- Secure Boot can interfere with custom GRUB entries. You may need to disable Secure Boot or sign your kernel.
- Always download ISOs from official sources to avoid malicious files.
If you are unsure about a parameter, test it in a virtual machine first.
Frequently Asked Questions
Can I boot any ISO with GRUB2?
No. Only ISOs that include the necessary kernel and initrd in a known location and are designed for live booting will work. Many popular Linux distributions support it, but some (like Windows) do not.
Do I need to edit /boot/grub/grub.cfg directly?
No. You should edit files in /etc/grub.d/ and run update-grub. Directly editing grub.cfg is discouraged because it is regenerated automatically and your changes will be lost.
Why does my ISO boot to a black screen?
This can be due to missing or incorrect kernel parameters, especially the iso-scan/filename or live-media option. Also, some graphics drivers may require adding nomodeset to the kernel line.
Can I boot a Windows ISO with GRUB2?
Booting a Windows ISO directly is not straightforward and generally not supported. GRUB2 can chainload the Windows bootloader, but that requires extracting the ISO contents to a partition, not loopback mounting.
Is it faster to boot from HDD than USB?
Usually yes, because SATA SSDs are faster than most USB flash drives. However, the difference is only noticeable during initial loading; live systems run from RAM after boot.
How do I remove the ISO entry later?
Simply delete or comment out the menu entry in /etc/grub.d/40_custom and run update-grub again.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.