This article presents a method for installing multiple (more than 2) operating systems on a single hard drive and creating a boot menu for selecting which operating system to boot. This method relies on a primary bootloader menu, stored in its own boot partition, which is used to "chainload" individual bootloaders which are unique to each independent operating system.

Chainload is similar to how it sounds. The master bootloader--most often GRUB installed on the MBR--presents a menu to the user. In this menu, there are options to boot each OS from its respective partition. Using chainloading, GRUB doesn't need to know exactly how to load each OS, it simply hands off control to the actual bootloader of the selected OS, in a chain-like fashion.

These instructions are for installing more than two OS's on your hard drive. If you only need two operating systems (such as a Windows installation and a (K)ubuntu Linux installation), it is easiest to just use the (K)ubuntu installer to do it for you (see WindowsDualBoot, for example).

Warning

This tutorial requires GRUB (GRand Unified Bootloader) version 1 (GRUB Legacy) to be used as the master bootloader.

As of version 9.10 (Karmic), the Kubuntu Desktop edition LiveCD installer uses Grub2 (which is harder to customize) and does not allow the specific steps needed in this tutorial. DO NOT USE the Karmic Koala Desktop edition LiveCD for installation if:

  • you have a dedicated boot partition
  • you use multiple OS (more than 2)
  • you already use chainloading of bootloaders.

The Ubuntu/Kubuntu Desktop edition LiveCD installer by default overwrites your Master Boot Record so that it points to its own partition (instead of to the boot partition) and you will subsequently be forced to re-create the Master Boot Record so it once again points back to the boot partition. (This is a serious flaw in Karmic Koala's Desktop edition LiveCD installer.) Instead, I strongly recommend using the Ubuntu Server edition LiveCD installer (and then later adding the ubuntu-desktop or kubuntu-desktop).

Introduction

The method here involves creating a small (approximately 100 Mb) boot partition in which to store the GRUB files. These files will be copied from the GRUB files that are created during the first Ubuntu Linux OS installation. The initial main GRUB menu will be kept in this small boot partition and will be edited so that GRUB will then chainload the bootloader files for whichever Windows, (K)ubuntu, or other Linux operating systems is chosen from the menu.

Each operating system then can keep the bootloader that is peculiar to it within its own partition. If the kernel, filesystem, or bootloader for one OS changes, it does not affect the ability of any other operating system to start, nor will it affect the primary GRUB bootup menu (which is stored and protected within its own boot partition).

This avoids the otherwise common problem that whenever a new OS (or distribution) is installed (including Ubuntu), it stores a GRUB configuration menu within its own partition and takes over the functions of the bootloader for every other OS. If there are multiple operating systems, it becomes difficult to remember which operating system's bootloader is the currently active one (that the Master Boot Record points to). With the chainloading method, you don't have to worry about that, anymore. You can upgrade or replace any OS and not worry about disturbing the ability of any other OS to load.

Here is some more info about this method:

Using GRUB Legacy for the boot partition

This method uses GRUB Legacy for the boot partition (because it is easier to customize). Starting with Karmic Koala 9.10, Ubuntu/Kubuntu uses GRUB2 by default (instead of GRUB Legacy), so only versions of Ubuntu/Kubuntu 9.04 or earlier can be used for installing GRUB Legacy to the boot partition.

The easiest way is to use an Ubuntu Server edition 9.04 LiveCD (which uses GRUB Legacy) to install the first instance of Ubuntu Linux. Use the minimal install (i.e. don't install any extra packages), in the interest of speed. Proceed with the installation instructions that install GRUB to the Master Boot Record, as well as installing a copy of GRUB Legacy to the local partition. Then copy the GRUB legacy settings to the boot partition as described. Edit the GRUB Legacy menu settings stored in the boot partition so that chainloading to each planned partition is enabled.

After this is finished, re-install your new version of Ubuntu/Kubuntu to the same partition (overwriting the 9.04 version in the process). However, this time do not allow the new installation process to overwrite the Master Boot Record. We want the Master Boot Record always to use GRUB Legacy, not GRUB2. Install GRUB2 (this time) to the local partition only.

Now the Master Boot Record will use GRUB Legacy (stored in the boot partition) merely as a chainloader to each subsequent partition, where that chosen partition's particular bootloader will then be run directly from the partition (no matter if it is a Windows bootloader, an Ubuntu bootloader, or a Mac bootloader).

Partition design

Note: If you are re-arranging (re-partitioning and re-formatting) your hard drive after already having a GRUB bootloader installed, you might not be able to boot into Windows (or anything else) until you re-install as part of a Linux OS re-installation. Panic not. Just proceed in a calm and orderly fashion.

Windows partitions

It is easiest if your Windows partition is the first one installed. This is because Windows installations are unpredictable -- sometimes your entire hard drive will be overwritten (causing you to lose any data stored there). Also, the Windows bootloader only looks in the first partition for a Windows installation.

If you have a brand new computer with no OS yet installed, the entire process is much easier. Create your partitions (using GParted) first, before installing Windows. Make the first partition NTFS (or the less secure FAT32, if you wish), intending it for the Windows installation. Then divide the remainder of the hard drive (using GParted) using the partitioning scheme noted above.

Generally, a retail "boxed" version of Windows (instead of an OEM or "backup" copy) installs quite happily to the first pre-configured, pre-sized partition. Go ahead and install it there, then skip on ahead to installing the Linux OSs.

However, some OEM and "backup" copies of Windows often have installation peculiarities (including pre-configured spamware, spyware, and specific hardware configurations) that will want to use the entire hard drive. Oh well, if you must, you must.

After doing so, you will then have to shrink the partition down to approximately 20-30 Gb (or your desired size).

Changing Windows partition sizes

Reinstalling Vista or Windows 7 on a new partition

A popular way to regain a significant amount of your hard drive with Vista/Windows 7 is to first re-format and re-partition the hard drive, then re-install Vista/Windows 7 second. When this works, you can reinstall Vista/Windows 7 in as little as 30 Gb.

For a re-installation, you will either need a retail version of Windows, or a "Recovery" disk provided by your OEM (computer) manufacturer that allows Windows re-installation to any size partition.

(Note: Not all Recovery disks will allow Windows re-installation to a newly re-sized partition. Although my eMachines, Dell, and Toshiba Recovery disks allowed it, my HP Recovery Disks did not. The HP Recovery disk, for example, erased the entire hard drive and recreated a single Windows partition. Any other partitions (and the data on them) were destroyed in the process. I therefore do not recommend using HP Recovery disks for this method. For HP computers, use the shrink volume method outlined above, instead).

For example, my eMachines box gave me the option of creating (burning) a pair of Recovery DVDs using eMachines -> eMachines Recovery Management. If your OEM manufacturer gives you a similar option of burning Recovery disks (instead of supplying Recovery CD/DVDs with your computer), make sure you burn these disks before reformatting/repartitioning your hard drive.

My OEM manufacturer (eMachines) had pre-installed both a primary partition and a recovery partition when I initially bought the computer. It is not necessary, however, to re-create these both of these partitions in order to re-install Vista from the Recovery disks; one partition for the re-installation is sufficient. As outlined below in my partitioning scheme, I reserved the first primary partition area (which you can either leave as free space at the beginning of the drive, or can format as an NTSC partition with the boot flag set, using GParted). Because I have a very large hard drive, I left 60 Gb for this first primary partition area that I planned to use as the Windows partition (although 40 Gb is probably more than enough, since my initial Vista re-install took only 22 Gb). The Recovery disks re-installed without problems, no matter which method I used (NTFS formatted partition or free space at the beginning of the drive), and I didn't have to worry about the MFT problem.

Obviously, this method would take an awful lot of work if you have been using your computer a long time. You would have to back up all your files first, and then re-install your add-on programs (again) after re-installing Vista/Windows 7. Then you would have to restore the files you had backed-up. It's much easier to do it with a new computer.

About Windows bootloaders

The Windows bootloaders store information about how big the partitions are. If you change the partition size, Windows checks the new partition size at the very next reboot (using either chkdsk in XP or a new utility in Vista/Windows 7). It then writes the info to its bootloader configuration file. If you start mucking around with other partitions before it has a chance to reset itself, the Windows bootloader will not be able to read the partition table properly (and will refuse to boot entirely).

GRUB boots Windows merely by chainloading the Windows bootloader (which is stored in the Windows partition). If the Windows bootloader doesn't work (i.e. doesn't recognize its own changed partition), then you are sunk.

If you ignore these warnings, I almost guarantee you will fry your Windows partitioning scheme and be unable to boot up Windows.

Install your first Linux OS

  • Read Using Grub Legacy for the boot partition to see why I recommend using Ubuntu Server edition 9.04 for this step.

  • Reboot into the Ubuntu 9.04 LiveCD (in my example I use the Ubuntu 9.04 Server edition 9.04 (Jaunty) LiveCD).
  • Install Ubuntu server -> (the usual pleasantries about language and mice and keyboards and stuff)

--> "Starting up the partitioner" -> Partition Disks: Manual

  • When you see the list of partitions, you will have to configure them appropriately.
  • You should note the small partition that you will use as the boot partition for the GRUB chainloader files. In my example it is /dev/sda2. Make a note of what yours is named.
  • Configure the swap partition.
  • This shouldn't need configuring if you set it up properly with GParted.
  • You can make sure that Use as: swap area is set.
  • Configure the root partition for the OS. Choose one of your logical partitions, which in my scheme is #6, is ext3, and has about 30 Gb.
  • Use as: Ext3 journaling file system.
  • Format the partition: Yes, format it
  • Mount point: / - the root file system
  • Bootable flag: off

Note: You should write down which device the / (root) partition is on. You will need this information later for GRUB settings. On mine, it is /dev/sda6.

-> Finish partitioning and write changes to disk -> "Installing the base system" -> ... ->

->"Install the GRUB boot loader to the master boot record?": YES -> Continue

  • In this step, GRUB must be installed both on the MBR (master boot record) as well as locally on the partition being installed (in this example /dev/sda6). The local version will be chainloaded by the MBR version. Therefore, install GRUB a second time:

-> Go Back -> Install the GRUB boot loader on a hard disk -> "Install the GRUB boot loader to the master boot record?": NO -> Device for boot loader installation: /dev/sda6 -> Continue

Copy boot files to the small GRUB partition

  • Boot into your Linux OS. Open a command line terminal if you have installed a desktop.
  • Make a new directory and mount it in your new Ubuntu OS.

 sudo mkdir /media/GRUBpartition
 sudo mount /dev/sda2 -t ext3 /media/GRUBpartition
 sudo mkdir /media/GRUBpartition/boot
 sudo mkdir /media/GRUBpartition/boot/grub

Note: Use whatever the device name of your small GRUB partition is (mine is /dev/sda2)

  • Make sure there are full read/write write permissions (this step may be optional).

 sudo chmod 777 /media/GRUBpartition/boot/grub
  • Copy all your GRUB files to the new partition

 sudo cp -r /boot/grub/* /media/GRUBpartition/boot/grub
  • Edit the menu.lst

 sudo nano /media/GRUBpartition/boot/grub/menu.lst
  • Place a chainloader entry as the first entry:

 ## ## End Default Options ##
 title  First Ubuntu Jaunty Server OS (chainloader)
 rootnoverify   (hd0,5)
 chainloader    +1

 title Second Ubuntu Jaunty Server OS (chainloader)
 rootnoverify   (hd0,6)
 chainloader    +1

This assumes your first installed OS has its / (root) directory in /dev/hda6 (as in my example above). GRUB counts the first partition as 0, so hda6 becomes (hd0,5), or hard drive 1 (it starts counting at zero), partition 6). If you want to chainload a bootloader on a second hard drive, partition 4 (/dev/hdb4), you would specify (hd1,3), instead, for example.

(I also put it an entry for my second planned OS, even though I haven't installed it yet. That will save me time later.)

  • Return the permissions so that only root can change or execute the files:

 sudo chmod 744 /media/GRUBpartition/boot/grub
 sudo chmod 744 /media/GRUBpartition/boot/grub/*

Reinstall GRUB to MBR

Now that the files are copied, we need to tell GRUB to look for them there. Do this step from your Linux OS command line terminal.

  • Start GRUB Legacy:

 sudo grub
 grub> find /boot/grub/stage1

You should see the places there are grub configuration files.

 (hd0,1)
 (hd0,5)

Note that (hd0,1) corresponds to the small GRUB partition (/dev/sda2), according to the counting method outline above. (hd0,5) corresponds to your first Linux OS (in the example /dev/sda6).

  • Make the small GRUB partition the loadable GRUB location.

 grub> root (hd0,1)
 grub> setup (hd0)
 grub> quit

==Install your second Linux OS== Again I'm going to use (K)ubuntu for the example, although any OS can now be installed.

  • Reboot into the Ubuntu LiveCD (I recommend a Server edition, because some Desktop editions overwrite the Master Boot Record automatically, which is not at all desirable at this stage).
  • Install Ubuntu server -> (the usual pleasantries about language and mice and keyboards and stuff)

--> "Starting up the partitioner" -> Partition Disks: Manual

  • When you see the list of partitions, you will have to configure them appropriately.
  • Configure the swap partition.
  • This shouldn't need configuring if you set it up properly with GParted.
  • You can make sure that Use as: swap area is set.
  • Configure the root partition for the OS. Choose one of your logical partitions, which in my scheme is #7, is ext4, and has about 30 Gb.
  • Use as: Ext4 journaling file system.
  • Format the partition: Yes, format it
  • Mount point: / - the root file system
  • Bootable flag: off

Note: You should write down which device the / (root) partition is on. You will need this information later for GRUB settings. On mine, it is /dev/sda7.

-> Finish partitioning and write changes to disk. (It is OK to format the swap and / (root) partitions.) -> "Installing the base system" -> ... ->

  • "Installing GRUB boot loader" ->

  • "Install the GRUB boot loader to the master boot record?": NO
  • "Install the GRUB boot loader on a hard disk": /dev/sda7

Use whichever device that corresponds to your / (root) directory for this OS, of course. This ensures that the GRUB bootloader is installed to this OS's partition, as well.

  • Finish installation and reboot. This system ought to be selected as the Second Ubuntu Jaunty OS, obviously.
  • Note: Once you have booted into this OS, you can now edit the chainloaded GRUB bootloader's local settings for this OS (at /boot/grub/menu.lst) as usual, as you can for the first installed OS as well.

Changing main GRUB boot menu settings

  • You can edit the local (chainloaded) GRUB boot menu for each Linux OS that uses GRUB Legacy (within the partition in which it is installed), if desired:

 sudo nano /boot/grub/menu.lst
  • You can edit the local (chainloaded) GRUB boot menu for each Linux OS that uses GRUB2 (within the partition in which it is installed), if desired (see these GRUB2 instructions):

 sudo nano /etc/default/grub
 sudo update-grub
  • To change the main GRUB boot menu, you will have to change the menu.lst found on the small GRUB boot partition.

  • If you are doing this from a Linux OS other than the first one you installed, again make a new directory for mounting:

 sudo mkdir /media/GRUBpartition
  • Mount the directory

 sudo mount /dev/sda2 -t ext3 /media/GRUBpartition

Note: Use whatever the device name of your small GRUB partition is (mine is /dev/sda2)

  • Make sure there are full read/write write permissions (this step may be optional).

 sudo chmod 777 /media/GRUBpartition/boot/grub/menu.lst
  • Edit the menu.lst

 sudo nano /media/GRUBpartition/boot/grub/menu.lst
  • Edit or add new chainloader entries:

 ## ## End Default Options ##
 title  First Ubuntu Jaunty Server OS (chainloader)
 rootnoverify   (hd0,5)
 chainloader    +1

 title Second Ubuntu Jaunty Server OS (chainloader)
 rootnoverify   (hd0,6)
 chainloader    +1

 title Newest Whizbang OS on second hard drive, partition 4 (chainloader)
 rootnoverify   (hd1, 3)
 chainloader    +1

GRUB starts counting from 0, so the first hard drive is number 0 and the first partition is also number 0. hda6 (which is hard drive 1, partition 6) becomes (hd0,5). If you want to chainload a bootloader on a second hard drive, partition 4 (/dev/hdb4), you would specify (hd1,3).

  • Return the permissions so that only root can change or execute the files (this step may be optional):

 sudo chmod 744 /media/GRUBpartition/boot/grub/menu.lst

Add Mac OS X Entry

  • You can add a chainloader entry for a Mac OS installation on a separate partition. In this configuration, Mac OS X must have its own bootloader at the beginning of the partition. Here's the entry for Mac OS X that is on partition /dev/sda9 (equivalent to (hd0,8):

 title Mac OS X
 root (hd0,8)
 makeactive
 chainloader +1

Re-installing GRUB Legacy after Windows Upgrade

  • Windows upgrades rewrite the Master Boot Record so that it points to the Windows bootloader only, instead of to the copy of GRUB in the boot partition. The Master Boot Record must therefore be re-written so that it will again point to the copy of GRUB stored in your boot partition.
  • For this example, assume the boot partition is the /dev/sda2 partition (which is known as (hd0,1) to GRUB Legacy).

You must use a version of a LiveCD that has GRUB Legacy, i.e. Kubuntu/Ubuntu 9.04 (Jaunty) or earlier. Start the LiveCD and start a command-line terminal (Terminal in Ubuntu or Konsole in Kubuntu). From the command-line terminal start GRUB:

 sudo grub

Then enter the commands to restore the Master Boot Record to point to the boot partition at /dev/sda2:

 > root (hd0,1)
 > setup (hd0)
 > quit
  • Reboot. Your previously created GRUB options should again appear.

Other resources


CategoryBootAndPartition

MultiOSBoot (last edited 2011-04-10 19:57:46 by tomdavies04)