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 Answers
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
setis used for storing the path of the ISO file into a variable, hereisofile.loopbackis 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)$isofilein which(hd0,5)represents the fifth partition of the disk.- Points to note: In
(hd0,5),
1st digit represents the device number which starts from0(here : 0 = 1st device) and
2nd digit represents the partition number which starts from1(here 5 = 5th partition).
That means/dev/sda5 - And variable
$isofilehas 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.
- Points to note: In
linuxcommand is used to load Linux kernel (vmlinuz) from file. Put the path of Linux kernel in the ISO.Read/extract the content of ISO to get the path of kernel example:
$ 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.netinstso,
/casper/vmlinuzwas used here.
initrdcommand is used to load an initial ramdisk for a Linux kernel image, and set the appropriate parameters in the Linux setup area in memory.- initrd is a scheme for loading a temporary root file system into memory. Put the path of
initrdin the ISO. Read/extract the content of ISO to get the path of
initrd:$ 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
- initrd is a scheme for loading a temporary root file system into memory. Put the path of
The additional parameter such as
boot=casper iso-scan/filename=$isofile noprompt noejectmay be specific to a GNU/Linux distribution and vary for another family of Linux. You can find some configurations for different family/distribution from here.Note: Some distributions use
initrd.gzorinitrd.lzdepending upon the algorithm/compression used.
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.
- 55,929
- 26
- 146
- 227
- 23,898
- 29
- 92
- 144
-
Wow, I'm impressed...I would have thought it would be impossible, since installing a new OS often involves reformatting partitions, which could include the partition your ISO file is stored on. – Wildcard Dec 24 '15 at 08:15
-
Your samples uses GRUB2. Centos 6 uses GRUB1 (grub legacy) and above examples doesn't work. – Ikrom Dec 04 '18 at 06:02
-
https://help.ubuntu.com/community/Grub2/ISOBoot – VidathD Jan 08 '21 at 04:28