📜 ⬆️ ⬇️

An interesting feature of Grub2: loading from ISO file

Actually, I wanted to look at Unity. According to the pictures and video - like nothing. Yes, here's the trouble. In the virtual machine you will not start it - 3D requires. I myself KDEshnik. The main OS on the laptop is kubuntu. Well, I think you can put the second system. Free space, like, there is.

OK. I shake the image of Natty, I burn it, but hell. It turned out my CD-ROM is not working. The laptop is already quite old. Boot from flash drives in the BIOS either. After a brief panic, a solution was found.

It turned out that grub2 learned to understand the ISO 9660 format and can load the OS directly from an ISO image located on a hard disk. As it turned out, not all systems are ready for this turn of events. Many for one reason or another are confused when loading. Fortunately, Ubuntu is not one of them.
')
Well, let's get started. First of all, add a new menu item to Grub2. To do this, edit /etc/grub.d/custom_40, adding the following lines to the end of the file:

menuentry "Ubuntu Live" {
set root=(hd0,7)
loopback loop /ubuntu-11.04-desktop-amd64.iso
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/ubuntu-11.04-desktop-amd64.iso noeject noprompt --
initrd (loop)/casper/initrd.lz
}

And what are we doing here:
In “set root” we indicate the partition in which the iso image is located
In the “loopback loop” we create a loop-device to which we are mounting our iso file (see, for example, the mount manual, the “Loop Device” section, if you don’t know what kind of loop device it is).
The next two lines indicate the location of the kernel and the initrd image relative to the loop device root (the path to the kernel files and the initrd inside the ISO image).

If anyone tries to repeat, keep in mind:

1. In set root = (hd0,7), replace the 7 with the partition number on your machine where the iso-image of the system is located. For example, if you downloaded ubuntu-11.04-desktop-amd64.iso into the / dev / sda1 partition, the line will change to set root = (hd0,1).
2. I downloaded the ISO to the root of my home partition (which is (hd0.7). If you have an image in any folder, specify the full path to the image relative to the root.

Update the grub2 configuration file:
update-grub

Actually, then I created a new partition for the future second system using fdisk, and rebooted.

As expected, a new item “Ubuntu Live” has appeared in the boot menu, which was immediately selected. When loading, no adventures happened, but instead of Unity I was met by Gnome :-) Firewood for my nvidia is not included in the distro.

It's time to start the installation. I press install. After selecting the sections for /, swap and / home, I was waiting for the next file. Ubiquity refused to continue for a period, arguing that I have a mounted partition. In order to create a loop device with our Ubuntu image, grub2 first mounted the partition on which this image was located. And it does not matter that this section did not figure in any way among those who claimed any modification during the installation, the installer of Ubiquity was adamant and the installation refused to continue.

After a brief search in Google, it turned out that I was not the first to encounter this. The problem was solved by removing the line with the mounted partition (in my case it was / dev / sda7) from / etc / mtab. It was necessary to do this before starting the installation. After its removal, everything went like clockwork. The installation was completed successfully, I installed the video card driver and after rebooting ... TA-DA.

image

After a successful experience with Ubuntu, I decided to see how versatile this boot method is. I am forced to report that many distributions do not have it all so smoothly.
First of all, grub2 must be installed in the main system (the one you use with the bootloader). Grub and the rest of the boot loaders do not know how to load the system from the ISO on the disk.

The problem is also that the developers of the distribution kit, which we load by this method, should obviously provide the option of loading from the ISO file. In Ubuntu, if you look at the line of the grub2 configuration file, which specifies the path to the kernel, you will see that the special parameter iso-scan / filename is passed to the kernel, which clearly indicates that the system is loaded from an ISO file.

Downloading from the ISO-file in distributions based on Ubuntu (Mint, Kubuntu, Mythubuntu, BackTrack ...) works. There is support for downloading from the ISO file in Gentoo, SystemRescueCD, several less famous distributions: Sidux, Grml, Xbmc. Also, this method can be used to download small distributions, which, after unpacking the initrd, are completely stored in memory and do not use files in the image. For example, CentOS, Debian (and probably many other distributions) have so-called “netinstall” images that contain only a minimum and all packages are installed over the network.

Fedora is not yet “able” to boot by this method (although the bug in their bug tracker is hanging and work is being done in this direction). Also this method does not work in Arch and Debian yet.

Source: https://habr.com/ru/post/118472/


All Articles