One of the great things about using Linux is that it comes in many versions. For every computer user, there's at least one, if not a few, distributions that suit his or her interests. Some prefer a desktop oriented system with office and multimedia applications. Other users want a distro designed for use in a music studio - complete with the latest digital audio workstation software. Computer security professionals find their needs are met with a distro focused on penetration testing. Selecting one distro isn't necessary - a better way to use Linux is to install one distribution for general computing and add others, as CD or DVD images, for more specialized tasks. Grub2 is a common bootloader for Linux systems and can relatively easily be configured to boot any number of disc images with just a little time editing and arranging the relevant files. Read onward to learn how it is done.
In the example given here, the computer has one hard drive, and it is divided into three partitions. The main system (either Linux or Windows) runs on the first partition and the second partition is the linux home folder. The third partition serves as storage for documents, backups, and "frugal" installation of multiple Linux distributions. The term "frugal install" means the distro is kept as a disc image (iso file) or the files are simply extracted and kept in compressed form. Be aware that the drive and partition numbering scheme is peculiar in Grub2: the first drive is "hd0" while the first partition is numbered "1" and so forth. In this tutorial, the first drive (hd0) and third partition (3) will be used. Systems to be added are: DreamStudio 12.04 (with the Unity Interface!), Kali Linux 1.0.5, MOFO Linux 2.0, Andy's Ham Radio Linux v14, and SLAX v7.08.
DRIVE CONFIGURATION: Drive #1 (hd0 to Grub2)... Partition 1: Main system files (Ubuntu) Partition 2: Main system home folder (user files and settings) Partition 3: ISO files for many specialist Linux Distributions (MOFO Linux, DreamStudio, Kali Linux, etc.)
#!/bin/sh 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. # These entries are for Linux frugal installs based on Grub2 USB multiboot # techniques. # Code updated 2021-03-28 to debloat and fix errors menuentry 'Kali Linux 6.0.0' { insmod ext2 set isofile="/isofiles/kali-linux-6.0.0-amd64.iso" loopback loop (hd0,3) linux (loop)/live/vmlinuz findiso= boot=live noconfig=sudo username=root \ hostname=kali vga=791 initrd (loop)/live/initrd.img } menuentry 'MOFO Linux 4.3' { insmod ext2 set isofile="/isofiles/mofolinux-4.3.iso" loopback loop (hd0,3) linux (loop)/boot/syslinux/vmlinuz from= nomagic base_only norootcopy \ zram=60% noauto timezone=GMT-0 login=guest initrd (loop)/boot/syslinux/initrd.xz } menuentry 'DreamStudio_Unity-13.04.0' { insmod ext2 set isofile="/isofiles/DreamStudio_Unity-13.04.0-lwks-amd64.iso" loopback loop (hd0,3) linux (loop)/casper/vmlinuz boot=casper iso-scan/filename= noprompt \ noeject initrd (loop)/casper/initrd.lz } menuentry 'Andys Ham Radio Linux v18' { insmod ext2 set isofile="/isofiles/andyshamradiolinux-18-64bit.iso" loopback loop (hd0,3) linux (loop)/casper/vmlinuz boot=casper iso-scan/filename= noprompt \ noeject initrd (loop)/casper/initrd.gz } menuentry "Slax 10.0.0" { insmod ext2 set isofile="/isofiles/slax-English-US-10.0.0-x86_64.iso" loopback loop (hd0,3) linux (loop)/slax/boot/vmlinuz from= slax.flags=perch,xmode nopersistent \ noeject noprompt noatime ro initrd (loop)/slax/boot/initrfs.img }
After editing /etc/grub.d/40_custom, open a terminal window and update grub2:
sudo update-grub
Yes, it is entirely possible to put Linux systems on a machine with Windows already installed! Similar to other dual boot setups, it is necessary to use disk partioning software to create a partition separate from Windows and install Grub2 as the bootloader on that partition. It is actually much like the dedicated USB installation shown below, but instead of a separate flash memory device, the files and bootloader are installed to an extra partition just above Windows. To boot windows, Grub2 is set up to chainload the Windows bootloader.
For accomplishing this sort of installation, you must correctly determine the partition to be used for holding the Linux iso files and Grub2 configuration files. This example depicts a hard drive with Windows on the first partition and Linux systems on the second. Expect Windows to occupy /dev/sda1; install Grub2 and Linux files to /dev/sda2.
We will next install Grub2 to the second partition on the hard drive. Boot the machine into Linux from a live DVD or USB stick, mount the partition, and then write the Grub2 data to the second partition as shown below:
1) Open the terminal and get root priveleges:
sudo su
2) Verify the location of the second drive partition:
fdisk -l
3) Set up a mount point to work on the partition. You may delete it later:
mkdir /mnt/NEWLINUX && mount /dev/sda2 /mnt/NEWLINUX
4) Install Grub2 to the drive:
grub-install --force --no-floppy --boot-directory=/mnt/SKYPARTITION/boot /dev/sda2
5) Create a directory to hold the iso files:
mkdir /mnt/NEWLINUX/isofiles
6) Using your file manager, copy and paste the Linux iso files into the "isofiles" directory in the partition.
7) Create a "grub.cfg" file located at /boot/grub/grub.cfg in the partition which will hold menu data and direct grub to boot using one or more isofiles. In this example we will configure for booting Skywave Linux, MOFO Linux, and Windows 7. Be aware that Grub counts drives starting at zero and partitions starting at one:
set timeout=20 set default=0 menuentry 'Kali Linux 6.0.0' { insmod ext2 set isofile='/isofiles/kali-linux-6.0.0-amd64.iso' loopback loop (hd0,3) linux (loop)/live/vmlinuz findiso= boot=live noconfig=sudo username=root \ hostname=kali vga=791 initrd (loop)/live/initrd.img } menuentry 'MOFO Linux 4.4' { insmod ext2 set isofile='/isofiles/mofolinux-4.3.iso' loopback loop (hd0,3) linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename= quiet \ splash threadirqs -- initrd (loop)/casper/initrd.lz } menuentry 'DreamStudio_Unity-13.04.0' { insmod ext2 set isofile='/isofiles/DreamStudio_Unity-13.04.0-lwks-amd64.iso' loopback loop (hd0,3) linux (loop)/casper/vmlinuz boot=casper iso-scan/filename= noprompt \ noeject initrd (loop)/casper/initrd.lz } menuentry 'Andys Ham Radio Linux v18' { insmod ext2 set isofile='/isofiles/andyshamradiolinux-18-64bit.iso' loopback loop (hd0,3) linux (loop)/casper/vmlinuz boot=casper iso-scan/filename= noprompt \ noeject initrd (loop)/casper/initrd.gz } menuentry 'Slax 10.0.0' { insmod ext2 set isofile='/isofiles/slax-English-US-10.0.0-x86_64.iso' search --no-floppy --file --set=root loopback loop (hd0,3) linux (loop)/slax/boot/vmlinuz from= slax.flags=perch,xmode nopersistent \ noeject noprompt noatime ro initrd (loop)/slax/boot/initrfs.img } menuentry 'Windows 7' { insmod part_msdos insmod ntfs set root='(hd0,msdos1)' chainloader +1 }
To run any of the installed Linux distros, simply boot the computer and await the appearance of Grub2's menu. It should list the main system and each distribution frugally installed. Select the desired distro, and observe a normal startup sequence. After a few seconds of the distro's pretty bootlplash or scrolling messages, the system should be ready to use.
Yet another option is putting multiple systems onto a large USB stick or SD card. In that case, you must install grub to the USB stick and then use the file "/boot/grub/grub.cfg" for the menu entries. There are computer users who actually use nothing but frugal installs on a large USB stick, with the hard drive strictly storing documents, multimedia files, and so forth.
To install Grub2 to the boot sector of a USB stick, you will plug in the stick, mount it, and then write the Grub2 data to the stick. In the following example, we'll install to a USB flashdrive plugged into a machine running Linux on the hard drive. The hard drive is "sda" and the USB stick is "sdb". The first partition on the USB stick is "sdb1".
1) Open the terminal and get root priveleges:
sudo su
2) Verify the location of the USB stick:
fdisk -l
3) Set up a mount point to work on the USB drive. You may delete it later:
mkdir /mnt/USBDRIVE && mount /dev/sdb1 /mnt/USBDRIVE
4) Install Grub2 to the drive:
grub-install --force --no-floppy --boot-directory=/mnt/USBDRIVE/boot /dev/sdb
5) Create a directory to hold the isofiles:
mkdir /mnt/USBDRIVE/isofiles
6) Use your file manager, drag and drop the iso files for your systems into the "isofiles" directory on the USB stick.
7) Create a "grub.cfg" file located at /boot/grub/grub.cfg on the USB stick which will hold menu data and direct grub to boot using one or more isofiles. In this example we will configure for booting MOFO Linux and Skywave Linux. Be aware that Grub counts drives starting at zero and partitions starting at one:
set timeout=20 set default=0 menuentry 'MOFO Linux 4.4' { insmod ext2 set isofile="/isofiles/mofolinux-4.4.iso" loopback loop (hd0,3) linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename= quiet \ splash threadirqs -- initrd (loop)/casper/initrd.lz } menuentry 'Skywave Linux 1.5' { insmod ext2 set isofile="/isofiles/skywavelinux-1.5.iso" loopback loop (hd0,3) linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename= quiet \ splash threadirqs -- initrd (loop)/casper/initrd.lz }
Test the USB stick by rebooting the computer system and making sure the BIOS is set to look for the stick as either a USB flash memory or as a hard drive on the system. If necessary, use "E" to edit the Grub commands at boot time and find out what works. Most problems involve pointing Grub to the isofile, then to the vmlinuz and initrd files within the iso.
There is no need to lose files you create or changes you make while operating your system from an iso file! Configure the system to boot with persistence enabled. In the persistent mode, new data and settings are written to a dedicated partition which holds them safely between shutdown and subsequent restarts. Sure, it is possible to manually save your files before shutting down at the end of a computing session, but why bother when persistent mode does it automatically? You can even install software and retain it for future computing sessions.
Persistence requires two things: a dedicated partition of at least 128 MB and an additional boot parameter. When setting up partitions, create one in EXT2 or EXT3 format and label it "casper-rw". Persistence can be added to an existing USB stick or SD card by creating a new partition and setting the label to "casper-rw". For best results, consider making the partition 1GB to 2GB in size. Then add "persistent" to the kernel boot options in grub2. At start-up, the system will find and use the partition for any changes made.
Good luck, and enjoy the convenience and robustness of having one or more operating systems frugally installed to
an inexpensive USB drive.
©2005 - 2023 AB9IL.net, All Rights Reserved.
About,
Contact,
Privacy Policy and Affiliate Disclosure,
XML Sitemap.