How to Boot Debian ISO File From Hard Drive With GRUB2

This tutorial will be showing you how to boot Debian ISO file directly from hard drive with the GRUB2 boot loader so you don’t have to create a live CD or live USB. It’s super easy to create a Linux live USB these days, you can do it with a graphical tool or from the command line. But what if you don’t have a USB flash drive around or you want to install Debian to your USB flash drive?

GRUB to the rescue

GRUB2 boot loader is able to boot Linux ISO image file directly from your hard drive.

  • GRUB2 supports many file systems, including but not limited to ext4, HFS+, and NTFS, which means you can put your ISO file on any of these file systems.
  • GRUB 2 can read files directly from LVM and RAID devices.
  • GRUB2 also has network support. You can load OS images from a network by using the TFTP protocol.

In this tutorial, we will only talk about booting ISO file from a local hard disk. To use this feature, you need to have a Linux distro with GRUB2 as the boot loader already installed on your computer.

How to Boot Debian ISO File Directly From Hard Drive With GRUB2

First, start your computer and boot your existing Linux distro. Download Debian ISO. You can use either the netinstall ISO or live CD ISO. You also need to download hd-media/initrd.gz and hd-media/vmlinuz from this page

  • initrd.gz is the initial ramdisk.
  • vmlinuz is the Linux kernel.

If you want a graphical installer that allows you to use a mouse to click, then download hd-media/gtk/initrd.gz and hd-media/gtk/vmlinuz instead. Put these three files into the same directory. Next, open up a terminal window and edit the /etc/grub.d/40_custom file with a text editor such as nano.

sudo nano /etc/grub.d/40_custom

In this file, we can add custom entries to the GRUB boot menu. In this case, we want to add an entry to boot a Debian ISO file. The following is an example.

menuentry "Debian.4 net-install.iso" {
        insmod ext2
        set root='(hd0,2)'
        linux /linuxbabe/vmlinuz
        initrd /linuxbabe/initrd.gz
}

debian grub iso boot

Explanation:

  • menuentry: This entry will be displayed on the GRUB2 boot menu. You can name it whatever you like.
  • The insmod command inserts a module. Since these three files are stored on my home partition, the ext2 module is needed. If these files are on a NTFS partition, then you need insmod ntfs instead.
  • The set command sets the second partition of my first hard drive as the root directory. (My home partition is the second partition of my first hard drive.)
  • The linux command loads a Linux kernel from the specified path. vmlinuz means a compressed Linux kernel executable that supports virtual memory. Letter ‘z’ indicates that it is compressed.
  • The initrd command loads an initial ramdisk from the specified path. It can only be used after the linux command has been run. The initial ramdisk is a minimal root file system mounted to the RAM.

Note that GRUB does not distinguish IDE from SCSI. In Linux, /dev/hda refers to the first IDE hard drive and /dev/sda refers to the first SCSI or SATA hard drive. If you use a NMVe SSD, it might be named as /dev/nvme0n1, /dev/nvme1n1 and so on. But in GRUB, the first hard drive is always referred to as hd0, no matter the interface type. Also note that partition numbers in GRUB start at 1, not 0.

To check your partition number, you can run lsblk or sudo parted -l command in the terminal window. You can also see it in Gparted partition editor, which can be installed by issuing the following command.

sudo apt install gparted

On my computer, vmlinuz,initrd.gz and the Debian ISO image are stored under/home/linuxbabe/ directory, but I have a separate home partition and it’s set as root in the GRUB config file, so the path should start with /linuxbabe, not /home/linuxbabe/.

Save and close the file. Then update GRUB boot menu with the following command:

sudo grub-mkconfig -o /boot/grub/grub.cfg

On Fedora, the command to run is:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

On Debian-based Linux distro, you can use the following command to update GRUB boot menu.

sudo update-grub

You can see from the output that GRUB added a new menu entry. (Newer versions of GRUB don’t show this message. )

debian boot iso grub2

Now restart your computer. At the GRUB boot menu, you can see the menu entry you just added. Note that you might need to press the right Shift key in order to bring up the GRUB boot menu when the computer restarts.

boot debian iso from hard disk

Select it and press Enter. The Linux kernel (vmlinuz) and initial RAM disk (intird.gz) will be loaded into memory. Then additional installer component will be loaded from the Debian ISO image.

Avoiding the Common Pitfall

You may have used the following code to boot Ubuntu ISO from hard disk and now you try to use the same syntax for Debian ISO.

menuentry "ubuntu-16.04-desktop-amd64.iso" {
   set isofile="/home/username/Downloads/ubuntu-16.04-desktop-amd64.iso"
   loopback loop (hd0,1)/$isofile
   linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile quiet noeject nopromt spalsh --
   initrd (loop)/casper/initrd.lz
}

It won’t work. If you use this syntax, you will get the following error after booting the Debian ISO.

No common CD-ROM drive was detected.

or

No medium found containing a live file system.

The reason is that the Ubuntu method uses Linux kernel and initial ramdisk inside the ISO image, but you must use hd-media/vmlinuz and hd-media/initrd.gz in order to boot Debian installer from hard disk. The Debian ISO image is the CD-ROM/medium required by Debian installer.

A Few Other Tips

If the three files are on the top-level directory of a disk partition, don’t leave out the beginning slash when specifying the path to vmlinuz and intird.gz. In other words, you need

linux /vmlinuz
initrd /initrd.gz

rather than

linux vmlinuz
initrd initrd.gz

If the three files are on an extended partition of MBR disk, the partition number starts from 5, instead of 1. For example, the first logical partition inside of extended partition will be numbered as 5; the second logical partition inside of extended partition will be numbered as 6.

If you have a SATA disk and an NVMe SSD inside your computer, the SATA disk is the first and the NVMe SSD is the second. The same goes for a USB drive and an NVMe SSD.

I hope this tutorial helped you boot Debian ISO image from hard disk by using the GRUB2 boot loader. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks.

Rate this tutorial
[Total: 12 Average: 4.6]

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here