...making Linux just a little more fun!

Two is better than one!

By Dr. S. Parthasarathy

Summary

This article introduces the concept of twin-boot (as opposed to dual boot). Twin-boot involves two (or more) Linux distros on the same machine, and two hard disk drives (optional but highly recommended). The distros are cleverly installed, so as to make the best use of the available hardware redundancy. You can do more, and do it faster, with this kind of an arrangement.

The twin-boot experiment

It all started when I was decommissioning my old, self-assembled PC. I was building another Linux box with bigger/better hardware. I got a 80 GB disk, to replace my old 40 GB disk, and a brand new motherboard with built-in sound interface, and a bigger RAM, and a brand new flat-panel LCD monitor. My God, I was rich! Those were good old days when a little was enough to make one feel at the top of the world. Instead of trading in the old (smaller) drive for a new drive, I decided to keep it with me. Moreover, Linux distros were getting easier and more accessible, courtesy of magazines like Linux for You. So, instead of installing just one distro, I chose to install two distros and learn how to handle both. These choices led me to the big question: What would be the best way to get the most out of the hardware and the software I now had with me? The rest of this article will explain what I did. It may give you some ideas and make you extract more out of your Linux boxes. The twin boot experiment itself is fun to go through, and will help you experience several finer points of how Linux works.

The term dual boot has traditionally been used to denote a system where we have Linux and the other black-box OS together. The term "twin boot" is introduced in this article, to denote an "unpolluted Linux box" (ULB), which has two Linux distributions (and no black-box OS). The twin boot concept helps us to effectively get rid of the cancer that has infected all of us. Additionally, twin boot systems have two separate hard disks, although it is possible to build twin boot systems on a single hard disk. Having two disks gives us some advantages, as we will see later. There could be several ways to install two Linux distros on a system with two drives. This article shows one way in which this can be done, and discusses the various issues involved. Of course, you can extend the idea to more than two distros, and maybe more than two disks, on the same machine.

A word of caution, before you start making your twin-boot system: Do not attempt this if you are a novice and not fully aware of how Linux works. Setting up partitions, setting up the boot loader, and fine tuning the installation etc., require some prior knowledge and experience in Linux troubleshooting and administration. All this is not rocket science, but you can still make serious blunders. So, be careful. Keep a Linux guru close by, as your helpline, if you are still learning the ropes. Since you will be working as root, most of the time, you have to be extra careful.

How to do this

The principle involved in this approach is to install the two distros on the same disk (in two different partitions, of course). We set up swap spaces for the two distros, on the other disk. We also make a partition whose mountpoint will be /home. This single /home will be shared by both the distros. For convenience, let us call the two distros distro A and distro B, and call the two drives drive P and drive Q. The architecture we choose would look like Figure 1. The dotted arrow-lines show that the same /home is shared by both distros. There are two swaps, one for each distro. (There is a reason for this.) Both distros sit on the drive Q (the bigger one), whereas the /home and swap partitions are on drive P (the smaller one). In fact, this arrangement is a modified form of the arrangement explained in an article which appeared in Linux for You (February 2009). A similar effort is also explained in the article located at http://www.go2linux.org/dual-boot-two-linux-distros-debian-and-mandriva. This article has a large number of screenshots, to make things easier for you.

In my case, distro A was OpenSUSE 11, and distro B was Ubuntu 9.04. The drive P was a 40 GB IDE drive, and drive Q was a 80 GB SATA drive.

figure-1
Figure 1: A twin-boot system

The major steps involved in creating twin-boot systems are:

  1. Create partitions on Disk P and Disk Q, as above.
  2. Install the two OSes on disk Q. Configure each OS to use the appropriate partitions. Create user accounts.
  3. Tweak GRUB's menu.lst file on the first OS, so that it can launch either OS interactively at boot time.
  4. Boot OS A, and verify that the intended partitions have been mounted as planned.

Use command "mount", or run "cat /etc/fstab". Reboot, and repeat with distro B.

Create partitions on P and Q : Use a live CD (e.g. Knoppix), since you do not have any OS installed on the system just now. The command fdisk -l will give a clear picture of all the disks and their available partitions. Here is what we would see, if we did a fdisk -l on our system:

figure-2
Figure 2: Layout of the partitions

Notice that we made just one partition for /home, but two partitions for swap. The recommended size of swap is still a matter of debate and confusion. I chose 2 GB for each swap (on /dev/sda), just to be safe. Each swap partition is reserved for a specific OS. It is not a good idea to make two OSes write on the same swap partition, because that can cause serious inconsistencies and problems. For instance, every time you shut down Linux properly and subsequently restart it, you get a clean swap partition. If a distro crashes or hangs or is abruptly shutdown, the swap space is not deleted, and may lead to inconsistencies at next reboot. A good article about swap can be found at http://www.xenotime.net/linux/doc/swap-mini-howto.txt.

Install the two OSes: While installing your OS, make sure you select the right device/partition and mountpoint for each distro. Do not select "format partition" for the /home partition.

Create user accounts on each OS: Each OS must have its own, distinct, user accounts. That is, you cannot have the same user name on both OS. This is because, when you create a user, the OS adds many hidden files (dot files), to store various configuration data. Such files may get messed up, if used with another OS for which they were not made. The /home on my machine looks like this:

figure-3
Figure 3: /home contents

As the names indicate, "drsuse" is the user on SUSE, and "drubuntu" is the user on Ubuntu.

Modify GRUB: Linux uses a boot loader called GRUB (GRand Unified Bootloader) to help you decide at boot time which OS should run. The behaviour of GRUB is defined in the file /boot/grub/menu.lst. The first Linux should install GRUB on the MBR. The second installed Linux should install GRUB on its root partition. Here is a screenshot of the menu.lst file on my first Linux (SUSE Linux):

figure-4
Figure 4: GRUB menu.lst file

Verify using mount or /etc/fstab: The "mount" command is a very useful command. You can call it without any arguments, in which case it will display all the mount points and their respective devices. By examining the mount output of both OSes, you can confirm that they are indeed using the partitions as you intended them to use. Here is a mount output of my second distro (Ubuntu): The file /etc/fstab keeps track of the various filesystems installed on the system. The file /etc/fstab is like the horoscope of your system. Each OS you install will have an /etc/fstab of its own. The /etc/fstab of Ubuntu is shown further below.

And this is the mount output of my first distro (SUSE) :

figure-5
Figure 5: mountpoints

Notice that on both distros /home is mounted on /dev/sda1. The SUSE / is at /dev/sdb1, and the Ubuntu / is on /dev/sdb2. Each distro has been given about 40 GB.

figure-6
Figure 6: /etc/fstab

We notice that Ubuntu's swap is /dev/sda3, and SUSE's is /dev/sda2

Why to do this?

It may sound strange to install two Linux distributions on the same machine, and have two disks where one would do. There are situations when this is meaningful. For instance, one would like to be familiar with the finer details of various Linux distributions. A good Linux professional has to be conversant with various distributions. We can get confidence only by actually working on them. It may be a good idea, or even the only way out, to have both distros on the same machine. We can thus switch distros, without physically switching between machines. Each distribution has its own package management mechanism. For instance, SUSE uses YaST, whereas Ubuntu and Debian look-alikes use APT. Each distribution has its favourite desktop interface. On SUSE, I use KDE. On Ubuntu, I use the GNOME interface. These two interfaces are so different from each other. The internal structure, file hierarchy, startup and shutdown sequences, and various configuration parameters are all different between distros. All distros do not carry the same set of applications. It is also practical to keep one distro as an experimental distro, on which we can try our several "what-if" scenarios, and keep one distro as a stable operational distro, for serious usage. So, it makes sense to have two distros on the same machine. On the other hand, keeping two hard disks is also useful. It would help maintain some kind of a backup mechanism, or a mirror, for fault-tolerant operations. The more ambitious user can also configure a RAID, if he/she has two drives. (Conditions apply.)

All Linux users know that /home is the directory where all non-root users' files are stored. Each user gets a sub-directory under this /home directory. All his/her files are stored inside this sub-directory and very well protected from other users. In addition, there are several configuration files specific to each user (usually, files with names starting with a period), all of which are stored in the respective user directories. Each distro needs a /home for its users, but it makes sense to use a single /home shareable by both distros. You save space, management is easier, taking backups is faster. By putting the /home on a separate partition (common to both distros), you obtain additional benefits: You can reinstall or change the distros at will, without risking /home. Disk access becomes faster, since accesses to /home do not clash with accesses to other parts of the distro, and swap operations do not compete with other operations on /home.

In a multitasking OS like Unix/Linux, your disk is constantly under pressure, to serve two competing and concurrent phenomena: process state transitions, and swapping (paging).

Process state transitions: In a multi-tasking OS, the OS keeps juggling between different tasks (processes), giving the user a feeling that all programs are running simultaneously. Processes are shuffled automatically and frequently between the main memory (RAM) and disk, and vice-versa. Remember, this phenomenon can occur not just because of your own applications, but also is provoked by other background processes running in the background. If you do a "pstree" or "ps -ef" command, you will be surprised to notice the amazing number of processes running. There is considerable disk activity going on because of this phenomenon.

Swapping (paging): At the same time, the disk is also required for another important function called "virtual memory". When the system is working on large chunks of data, or data that require huge disk space, available RAM may not be adequate. This can occur in situations like when you are trying to invert a very large matrix, say a 10000 x 10000 real matrix. You may be working with image-processing applications that handle large images. If your RAM is not enough, the OS automagically and cleverly moves unused/unneeded data out to the hard disk, and brings this data back to RAM whenever needed. The data is temporarily parked on the disk, in a special area appropriately called the "swap area" (or swap).

Your system performance can be considerably reduced, if the above two phenomena are too frequent and occur simultaneously, and on the same disk. You will notice long periods of silence from your system, as it recovers from the above two competing activities. In the arrangement explained in Figure 1, since the swap is on a different drive, access to the swap will not be affected by access to the disk due to process switching (and vice-versa). Your system will appear to run faster!

Wrap-up

The author invites comments, queries, and suggestions from readers of this article. The author thanks his friends, P.S. Prasad and Suresh Ramasubramanian, for helping him out when he got into dead-ends in this experiment.


Talkback: Discuss this article with The Answer Gang


[BIO]

Parthasarathy is an aggressive supporter of FOSS. He teaches discrete mathematics, and preaches LaTeX and Linux, to students of Computer Science. He contributes in various forms, to make Linux "more enjoyable for more people". His website : http://algolog.tripod.com/linux1.htm will give more specific details about him. His contact address is : drpartha@gmail.com


Copyright © 2009, Dr. S. Parthasarathy. Released under the Open Publication License unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 167 of Linux Gazette, October 2009

Tux