GRUB

Installing Multiple Distributions on the same computer Sanket Totewar

ith availability of the internet, requires some familiarity with computer jar- has become accessible to nearly all gon and is not for the faint-hearted. It also Wthe parts of the world. And with the requires a brief understanding of partitions great freedom that this of- as well as boot loaders. Plus there is a very fers, we can see a steep rise in the number of rare chance of losing data while playing with distributions released the world over. The five partitions. So, it is a good idea to back up all distributions shipped with this issue have al- important data before advancing any further. ways competed with each other for the num- ber one position. This has lead to new features Boot loaders and services emerging with every release. So, Let us see what happens in most cases to make the most of the services offered by when we turn on our computer. It is the job various distributions, most users often tend of the BIOS to find the primary bootable de- to install multiple distros and switch between vice (usually a hard disk) and load the initial them. This is commonly referred to as distro bootstrap program from the MBR. The MBR hopping and is a common practice between is an abbreviation for newbies and experts alike. and is the first 512 bytes of the hard disk. This area stores a boot loader program Synopsis whose purpose is to load the operating sys- This article is geared towards helping you tem and transfer execution to it. The operat- seamlessly install and run multiple Linux ing system then initializes itself by loading distributions on the same computer. Also the necessary drivers and programs needed we shall tackle cases where MS Windows or for its normal operation. In case of multiple other operating systems are to be present operating systems, the main boot loader on the same PC. In the article, I am taking transfers control to other operating systems Windows as an example, because it is the or their individual boot loaders depending most common case. on the computer configuration. Although great care has been taken to The boot loader is hence a very important explain various concepts in detail, this article utility for a Linux distro hopper. Various distri- butions use a variety of boot loaders like GRUB and LiLo for the above mentioned purpose. Of these, GRUB is known to be very popular due to its stability and multi-boot support. GRUB is an abbreviation for Grand Unified Boot loader and is used by GNU and most Linux distribu- tions. Recently, GRUB 2 has replaced older versions of GRUB which are now called GRUB legacy. GRUB legacy is no longer being devel- oped and GRUB 2 has found its way to being the default boot loader being shipped with popular distributions like . GRUB 2 offers a lot of advantages over other boot loaders. GRUB 2 has a variety of built-in programs and commands that can be used to boot into various operating systems. It Figure 1. YaST Partitioner in Action recognizes filesystems of almost all Linux, Win-

14 linux identity set GRUB

dows, Mac, BSD and Solaris systems. It is also possible to boot into a CD/ DVD image file like ISO using GRUB 2. It is also very customizable and gives you a choice to display background images. But before we look into the in- Figure 2. − Case 1 stallation of GRUB 2, let’s take a look at the various types of partitions. Partitioning Your hard disk can be divided into a number of separate portions that have their own identity. They are called Figure 3. Disk Partitioning − Case 2 partitions and are useful for installing operating systems as well as storing partitions (1) and (2) are reserved for Note: It is a good idea to in- data. There are two main types of par- MS Windows. The third primary parti- stall Windows before the Li- titions: primary and extended. A hard tion (3) can be used for shared data. nux distribution as it will replace the disk can be divided into a maximum It is a good idea to keep the shared MBR with its own entries. of four primary partitions or three pri- data as a primary partition so that it mary partitions and one extended. can be kept separate from the op- (Cases 1 & 2) Primary partitions are easily boot- erating systems. To ensure that this In the above cases, there is a special able and are used to install operat- data can be accessed in all operat- way of installing the Linux distribu- ing systems. Extended partitions, on ing systems, you can choose Fat 32 tions. The boot loader of only one dis- the other hand can be divided into a or NTFS as the . tribution can be installed in the MBR. number of sub-partitions called logi- The remaining space is converted This distribution will be responsible cal drives. Logical drivers are usually into an extended partition (4). This for updating the boot loader configu- used to store data or install second- partition consists of six logical drives ration files. Whenever we install or ary operating systems. Partitioning (5 to 10). The first logical drive (5) is remove various kernels or distribu- can be achieved using GParted, YaST for the system swap. I have kept this tions, this activity has to be triggered. Partitioner (Figure 1) or a similar pro- as the first logical drive as one doesn’t This is because the main boot loader gram bundled with distributions in tend to introduce changes in the size will never know about the changes the DVD. It is a very good idea to first of the swap. The other drives are for made in other operating systems. resize and create the partitions and the various Linux distributions that Windows uses its own boot then install all operating systems. you shall install. The number of logical loader which is saved on the system Also you should all your parti- drives may vary depending upon how partition or the System Reserved tions to avoid any confusion. many distributions you want to try. partition. However, for multi-booting One specific advantage of Linux Linux distributions, you shall have to distributions is that it can be in- Case 2 use the boot loader of one of the Li- stalled on primary partitions as well Installation on an empty hard disk. nux distributions. If you are installing as logical drives. There are various This case gives us the advantage Ubuntu as one of the distributions, ways of installing them based on of creating a partition table of our it is a good idea to install its boot your current partition table. Let us choice. Figure 3 shows a partition loader in the MBR. This is because see a few common cases in which table where I have installed Win- Ubuntu by default contains GRUB 2 our mission can be accomplished. dows (1) and one main Linux distri- which is our preferred boot loader. bution (2). While installing Windows, The boot loaders of the other distri- Case 1 I ensured that it is uses one partition butions must be installed on their re- Windows or another operating sys- only for its boot loader as well as spective logical drives containing the tem already installed on the comput- system files. I am resolving to retain root partition. Now your computer er. As we all know, Windows tends to these operating systems for a long will show you the GRUB 2 menu to occupy the first primary partition for time and hence they are on primary choose from all the existing OS. its system files. And some versions partitions. The primary partition (3) GRUB 2 installed by Ubuntu will of Windows (like ) also having a NTFS filesystem contains recognize the different kernels of the create a primary partition named shared data. The remaining space Linux distributions as well as other System Reserved for its normal work- has been converted into an extend- operating systems. However, it does ing. So we are usually left with one ed partition (4). Logical drive (5) is not check for them at every boot. Af- primary and one extended partition for Linux swap and is accessible for ter installation, GRUB 2 generates a for installing Linux distributions. all distributions. Logical drives (6) to grub.cfg file that contains this infor- Figure 2 shows the disk partition- (9) contain other distributions that I mation. This file is updated automati- ing map for case 1. Here, the first two may not retain in the long run. cally every time you install a new ker-

www.linuxidentity.com 15 GRUB

that the installation is successful. On entering the partition, you will see a directory /boot that contains neces- sary GRUB 2 files. When you reboot the computer, you will be taken to a GRUB prompt. You can easily enter Figure 4. Disk Partitioning − Case 3 any operating system directly by load- ing a kernel and using the boot com- nel in Ubuntu. But how will GRUB 2 systems. Note that all the Linux dis- mand. However it is recommended to know about the changes made in tributions were installed with the de- generate a grub.cfg file that shows a other distributions? There is a simple fault boot loaders in their respective menu at every system boot. command for this. All you have to do is partitions. Some booting options can log into your Ubuntu installation and also be changed after installation of GRUB menu entries enter the command line. In the Termi- the system. A good example is the The above commands just install nal, simply type update-grub which YaST boot loader configuration menu GRUB 2 on the partition and MBR. will automatically update the grub. as shown in Figure 5. This however does not create the cfg file. The update-grub command configuration file grub.cfg that is es- requires root privileges and you may Installation of boot sential to show a menu during boot. loader on partition have to add sudo as a prefix. This file can be easily prepared us- The latest GRUB 2 boot loader can ing a text editor like gedit. Just en- Case 3 be manually installed by download- ter the btldr/boot/grub directory Installation of the boot loader in a ing from the GNU website. It should and create an empty text file having separate partition. This is a special be unpacked, installed and config- grub.cfg as its name. Here we can case where I created a separate parti- ured for the MBR. But it is easier to create menu entries for chainload- tion for the main boot loader GRUB 2. install it via the Ubuntu Live session ing to other operating systems. This boot loader is installed in the instead as you already have it readily MBR and is executed first on every available. Changing the default boot Tip: You can also run the boot. And depending upon its config- loaders for the other distributions is grub-mkconfig command uration file, it will hand over execution not recommended as GRUB 2 might and direct it to our boot loader par- to the other system boot loaders. not be supported in them yet. tition. But this has to be done only Figure 4 shows a partition table Boot into the Ubuntu Live session from a native Ubuntu or Debian in- where I have made a special parti- and open a terminal. Type grub-ins- stallation. First make sure that the tion for the boot loader. Windows and tall –version to find the version of boot loader partition is mounted. shared data are installed on other the existing GRUB installation. Mount Then run the command sudo grub- primary partitions. The extended par- the partition for installation of the mkconfig –o /media/btldr/boot/ tition houses Linux swap and the Li- boot loader. Here I have labeled my grub/grub.cfg which will update nux distributions. The biggest advan- boot loader partition as btldr and it this file automatically. tage of such a system is that the re- exists at /dev/sda1. Here sda states moval of any operating system does that it is the first sata hard disk. If GRUB naming convention is very not hamper my ability of booting into you are unsure about the position of simple to interpret. GRUB uses hd other systems. I thus have complete your partition, check it using either for a hard disks and the drive num- control over booting my operating GParted or the command sudo bers are counted from zero based -l in the Termi- on their BIOS order. The partitions nal. Now use in the hard disk are numbered from the command one based on their position. Hence grub-install the third partition on the second –root-direc- hard disk is denoted as (hd1,3). tory=/media/ I have a Windows partition at btldr /dev/sda (hd1,3) with NTFS as the file system. to install GRUB 2 So, the menu entry for the same will in the MBR and be as follows: its files on the defined parti- menuentry “ My Windows ↵ tion. The termi- Installation ” { nal should give a insmod message Instal- set root=’(hd1,3)’ lation finished. drivemap -s (hd0) ${root} No error report- chainloader +1 Figure 5. YaST Boot Loader Configuration ed which means }

16 linux identity set GRUB

The chainloader command tells boot loader, that boot loader will get menuentry “Sanket’s openSUSE ↵ GRUB 2 to hand over the control to activated and you will see its menu Installation”{ the first few bytes of that specific now. This will go on till Windows or a insmod partition. The drivemap command Linux kernel is selected. The selected set root=’(hd0,7)’ in GRUB 2 is useful for chainloading operating system will then be loaded. chainloader +1 operating systems like Windows es- } pecially when it does not reside at Real Life Scenario the first drive. Figure 6 shows a partition table menuentry “Sanket’s Linux ↵ I have an openSUSE installa- where I had only Linux distributions Installation”{ tion at (hd0,7) with file system. installed on this disk. The boot insmod ext2 GRUB recognizes all file systems loader is installed in the MBR while set root=’(hd0,8)’ above ext2 as an ext2 file system. So, its files are saved on this partition. chainloader +1 the menu entry will be as follows: The other two primary partitions } are for Linux swap and my Ubuntu menuentry “ My openSUSE ” { installation respectively. I have di- menuentry “Windows XP on 160 ↵ insmod ext2 vided the extended partition into GB”{ set root=(hd0,7)’ four logical drives. Of these, two insmod ntfs chainloader +1 are responsible for storage while set root=’(hd1,1)’ } the other two contain openSUSE drivemap -s (hd0) ${root} and Fedora installations. chainloader +1 Entries can similarly be created My Windows XP installation is } for other distributions too. Copy present on the second disk i.e. at the entries to the grub.cfg file and (hd1,1). For the above partition ta- One day, I decided to remove Ubun- save it. The order of the copied en- ble my grub.cfg file at /btldr/boot/ tu and install Mandriva instead. I tries depicts the order in which the grub has the following entries: was able to accomplish this easily entries will be shown in the boot due to the separate boot partition. menu. ##// GRUB 2 configuration file ↵ All I had to do was edit a few lines in To make a certain entry as the //## the configuration file. There is no default highlighted entry in ev- ##// manually created by SuNk8 ↵ worry about facing boot problems ery boot, adding the following line //## just because I removed my main to the beginning of grub.cfg: set distribution. Here 2 implies that default=”2” set default=”2” Further reading the third entry is to be highlighted set timeout=7 as counting is done from zero. JJ http://www.gnu.org/soft- The following command when menuentry “Sanket’s Ubuntu ↵ ware/grub/ added will set a timeout in sec- Installation”{ JJ http://members.iinet. onds for the highlighted entry. As insmod ext2 net/~herman546/ soon as the timer reaches zero, the set root=’(hd0,6)’ JJ https://help.ubuntu.com/ highlighted entry will be activated: chainloader +1 community/Grub2 Set timeout=7 Here 7 implies that } seven seconds will pass before the highlighted entry is selected. This is how we make a minimal grub.cfg file. More options can be added to this file to improve the user ex- perience during booting. Also we can have a beautiful background image while the timer is running. These tutorials are however out of the scope of this article. Booting (Case 3) Here when the computer starts, you will be taken to a GRUB 2 boot menu depending on your configuration file. You can choose and entry using your keyboard keys. Or the default entry will get activated after the timeout. If the selected entry leads to another Figure 6. Using GParted to resize and create partitions

www.linuxidentity.com 17