🐧 How to run any Linux distribution directly from your hard drive on Ubuntu using the Grub menu

Most Linux distributions provide ISO files that are designed and built to run in real time directly from bootable media such as CD / DVD, flash / USB stick, or even directly from hard drive using Linux Grub menu without the need burn it to CD / DVD or create a bootable USB.

This tutorial will focus on a way to launch some Linux ISO distributions directly from your hard drive by editing the Ubuntu 20.04 GRUB2 menu (runs on Ubuntu 18.04 or earlier), which is the default bootloader on most modern Linux distributions, making it faster the way you use the Linux operating system and also has a big privacy impact as all your settings and live sessions are not saved by default.

This section presents the CentOS, Fedora, Kali Linux, and Gentoo Live DVD distributions.

Requirements

Ubuntu 20.04 (or any other Linux distribution with GRUB2 bootloader) installed on your system’s hard drive.

Step 1.Download ISO Live files

1. To be able to download and run any Linux distribution without installing it on your hard drive, be sure to download the Live CD / DVD version for each Linux ISO image.

Step 2: add ISO images to the GRUB2 menu

2. After you have downloaded your favorite Linux ISO Live DVD images, open Ubuntu Nautilus as root with “sudo nautilus” from Terminal and create a directory named live at the root of your system and move the ISO file to that folder.

$ sudo nautilus

🐧 How to run any Linux distribution directly from your hard drive on Ubuntu using the Grub menu

🐧 How to run any Linux distribution directly from your hard drive on Ubuntu using the Grub menu

3. To continue, you need to provide Grub2 with the UUID of our disk partition – a universal unique identifier (the partition where the ISO files are located). To find the UUID of a section, run the following blkid command.

$ sudo blkid

For an auto-mountable partition or hard drives, run the following cat command at system boot. 4. Another way to get the UUID of your partition is to open the visualization of the contents of the grub.cfg file located in / boot / grub / path and search for —fs-uuid 5. After getting the UUID of the root partition, change to the /etc/grub.d directory /, open the 40_custom file for editing and add the following lines to the end of this file.

menuentry 'CentOS 8 Live' --class os --class gnu-linux --class gnu --class os --group group_main {
                set isofile="/live/CentOS-8-x86_64-1905-dvd1.iso"

         insmod ext2
         insmod loopback
         insmod iso9660      
                loopback loop (hd0,msdos1)$isofile      
                search --no-floppy --fs-uuid --set=root 3b87d941-8ee7-4312-98fc-1f26828d62ab                            
                linux (loop)/isolinux/vmlinuz boot=live fromiso=/dev/sda1/$isofile noconfig=sudo username=root hostname=centos
                initrd (loop)/isolinux/initrd.img
}

Here the following directives represent the following:

  • set isofile = Variable that stores the ISO system path.
  • (hd0, msdos1) = The first partition from the first hard disk (on Linux, disks are numbered starting from 0) – the same as / dev / sda1.
  • –Fs-uuid –set = root 59036d99-a9bd-4cfb-80ab-93a8d3a92e77 = First partition with the UUID of the first hard drive.
  • linux and initrd = Custom kernel boot parameters – they are different depending on the Linux distribution.
$ sudo update-grub

7. To start the CentOS Live ISO, restart your computer, select the CentOS entry from the GRUB menu, then press the Enter key.

In the same way, you can add other Linux Live ISO images to the GRUB2 menu as shown.

Open and edit the /etc/grub.d/40_custom grub file again and add the following entries.

For Fedora Live DVD

menuentry 'Fedora Live' --class os --class gnu-linux --class gnu --class os --group group_main {
                set isofile="/live/Fedora-Workstation-Live-x86_64-32-1.6.iso"

         insmod ext2
         insmod loopback
         insmod iso9660      
                loopback loop (hd0,msdos1)$isofile      
                search --no-floppy --fs-uuid --set=root 3b87d941-8ee7-4312-98fc-1f26828d62ab                            
                linux (loop)/isolinux/vmlinuz boot=live fromiso=/dev/sda1/$isofile noconfig=sudo username=root hostname=fedora
                initrd (loop)/isolinux/initrd.img
}

For Kali Linux Live DVD

menuentry 'Kali Linux Live' --class os --class gnu-linux --class gnu --class os --group group_main {
                set isofile="/live/kali-linux-2020.2-live-i386.iso"

         insmod ext2
         insmod loopback
         insmod iso9660      
                loopback loop (hd0,msdos1)$isofile      
                search --no-floppy --fs-uuid --set=root 3b87d941-8ee7-4312-98fc-1f26828d62ab                            
                linux (loop)/live/vmlinuz boot=live fromiso=/dev/sda1/$isofile noconfig=sudo username=root hostname=kalilinux
                initrd (loop)/live/initrd.img
}

For Gentoo Live DVD

menuentry 'Gentoo Linux Live' --class os --class gnu-linux --class gnu --class os --group group_main {
                set isofile="/live/livedvd-amd64-multilib-20160704.iso"

         insmod ext2
         insmod loopback
         insmod iso9660      
                loopback loop (hd0,msdos1)$isofile      
                search --no-floppy --fs-uuid --set=root 3b87d941-8ee7-4312-98fc-1f26828d62ab                            
                linux (loop)/live/vmlinuz boot=live fromiso=/dev/sda1/$isofile noconfig=sudo username=root hostname=gentoo
                initrd (loop)/live/initrd.img
}

8. Then refresh the GRUB menu again, reboot your computer, and select your preferred Linux distribution ISO from the GRUB menu.

$ sudo update-grub

9. If you do not have enough free space on the root partition, you can add another hard drive to place other Linux ISO files and move all the ISO files of your Linux distribution there. After creating the partition and adding the filesystem, mount it at / mnt to make it accessible.

$ sudo mount /dev/sdb1 /mnt

10. Then move all ISOs to the new hard drive and get its UUID using the blkid command.

$ sudo blkid

11. Reopen and edit the /etc/grub.d/40_custom grub file and add other Linux Live ISO images to the GRUB2 menu using the same procedure, but note the Live Kernel boot options for each distribution, which can be verified by installing the image ISO. use the mount -o loop option or refer to the distribution wiki pages.

Sidebar