How to run the ISO file directly from the hard disk using GRUB 2
Most Linux distributions provide a live environment that can be started from USB so that users can test the system without installation. We can use it to evaluate this release or simply use it as a one-time system, and it is easy to copy these files to a U disk. In some cases, we may need to run the same or different ISO images frequently. GRUB 2 can be configured to run a live environment directly from the boot menu, without burning these ISO to the hard disk or USB device.
Obtain and check the launched ISO Image
To obtain an ISO image, we usually need to visit the website of the required release to download image files compatible with our architecture. If the image can be started from the U disk, it should also be able to be started from the GRUB menu.
After the image is downloaded, we should check its integrity through MD5 verification. This will output a series of numbers and letters.
Compare the sequence with the MD5 Verification Code provided on the download page. The two should be identical.
Configure GRUB 2
The ISO image file contains the entire system. All we need to do is to tell GRUB 2 where to find the kernel, initramdisk, or initram File System (depending on the release we are using ).
In the following example, A KUbuntu 15.04 live environment will be configured to the Grub boot menu item of the Ubuntu 14.04 machine. This should be able to run on most new Ubuntu-based systems. If you are using other systems and want to implement other things, you can learn more from these files, but this requires you to have a little GRUB experience.
File in this examplekubuntu-15.04-desktop-amd64.iso
Placed in/dev/sda1
Of/home/maketecheasier/TempISOs/
.
To make GRUB 2 find it correctly, we should edit
/etc/grub.d40-custom
menuentry "Kubuntu 15.04 ISO"{
set isofile="/home/maketecheasier/TempISOs/kubuntu-15.04-desktop-amd64.iso"
loopback loop (hd0,1)$isofile
echo"Starting $isofile..."
linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=${isofile} quiet splash
initrd (loop)/casper/initrd.lz
}
Analyze the above Code
First, a variable name is set.$menuentry
This is the location of the ISO file. If you want to change the ISO, you should modifyisofile="/path/to/file/name-of-iso-file-.iso"
.
The next line specifies the loopback device and must provide the correct Partition Number.
loopback loop (hd0,1)$isofile
Note that hd0, 1 is very important here, it means the first hard disk, the first partition (/dev/sda1
).
The name of GRUB is a bit confusing here. For a hard disk, it starts counting from "0". The first hard disk is #0, and the second disk is #1, the third part is #2, and so on. However, for a partition, it starts counting from "1". The first partition is #1, and the second partition is #2. So on. There may be a good reason, but it is definitely not wise (obviously the user experience is terrible )..
In Linux, the first hard disk, the first partition is/dev/sda1
But in GRUB2 it ishd0,1
. The second hard disk, and the third partition ishd1,3
, And so on.
The next important line is:
linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=${isofile} quiet splash
This will load the kernel image. In the new Ubuntu Live CD, the kernel is stored in/casper
Directory and name itvmlinuz.efi
. If you are using another system.efi
The extension or kernel is stored elsewhere (you can use the archive manager to open the ISO file in/casper
). The last option,quiet splash
Is a general GRUB option. It doesn't matter if it is changed.
Last
initrd (loop)/casper/initrd.lz
This loadinitrd
It is responsible for loading RAMDisk to memory for startup.
Start the live System
After completing all the above steps, you need to update GRUB2:
sudo update-grub
After the system is restarted, you can see a new GRUB entry that allows us to start the newly configured ISO image:
Selecting this new entry allows us to start a live environment from a DVD or USB disk.
Via: https://www.maketecheasier.com/run-iso-files-hdd-grub2/
Author: Attila Orosz Translator: Locez Proofreader: wxy
This article was originally compiled by LCTT and launched with the honor of Linux in China
This article permanently updates the link address: