Introduction and Context

EDIT: This other page describes some portions of this procedure in more detail. A merge would be useful: MultiOSBoot. (oops, I found this page after writing this one)

I've been meaning to write this tutorial for a long while now. With the recent introduction of Grub2 into the Ubuntu community, I found it extremely frustrating to do what I had previously been doing with the legacy grub system. Don't get me wrong, Grub2 is a step in the right direction, but for me (and possibly others), I found Grub2's lack of control frustrating for what I'm accustomed to doing. (See Step #4, (ii) for additional notes)

Define: "Master Boot" -- This is the boot loader which is first loaded from the Master Boot Record (MBR). The purpose of this partition is to chainload the boot process to any number of operating systems without relying on any one operating system.

Why this "Master Boot Loader" thing?: OS installations can come and go, and if one gets blown away (or dies), we don't want to be stuck without a boot loader, unable to load any other operating systems! The concept of a "master boot loader" allows all operating systems to be bootable regardless of the state of any other operating system. That is to say, our "master boot loader" is decoupled from any individual operating system.

How does this affect the other OS-coupled boot loaders?: Not at all. In fact, it allows each of your individual boot loaders per operating system to be completely unaware of any other operating systems if you so choose. They can have all of their defaults, including those pesky growing kernel entries. The best thing to do is hide by default the individual OS-coupled boot loader menus because in most cases, they're irrelevant.

Multi Boot and the Master Boot Loader -- A Simplified Dual Boot Scenario

My actual setup consists of multiple operating systems, and the partitioning scheme is a little complicated, so for this tutorial, I will simply to the following concepts:

  • Dual-boot: Windows & Ubuntu Linux

  • "Master Boot Loader"

In other words, a "dual boot" scenario with a concept I call "Master Boot Loader".

(!): Please keep in mind through, that this solution scales to any number of operating systems.

To achieve this goal, consider the following basic partitioning scheme:

$ sudo fdisk -l

Disk /dev/sda: 163.9 GB, 163928604672 bytes
255 heads, 63 sectors/track, 19929 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00083ee8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       14648   117660028+   7  HPFS/NTFS
/dev/sda2           14649       14664      128520   83  Linux
/dev/sda3           14665       19644    40001850   83  Linux
/dev/sda4           19645       19929     2289262+  82  Linux swap / Solaris


OK what are all of these partitions for?






First partition because Windows will cry otherwise


"Master Boot Partition"

I like to wedge the "master boot partition" between Windows and Linux


Ubuntu Linux

Our operation system of choice. Smile :-)


Linux Swap

Swap (if required)

High level order of operations:

  1. Configure Partitions
  2. Install Windows OS
  3. Install Ubuntu Linux OS
  4. Configure the "Master Boot Loader"

(1) Configuring the Partitions

Configuring partitions has been covered extensively already, so I won't re-invent the wheel here. How you'll partition for multi-os is completely dependant on your OSs, how many of them, etc. Google is your friend if you're new to this.

Some tips:

  • Windows partitions typically need to go first, and must be on a primary partition.
  • Stick the 128MB "Boot Master" partition after Windows as type=ext2.
  • Mac/Linux/BSD can follow (possibly in logical partitions)

  • Swap can go at the end

If you're unfamiliar with this process, here are some helpful articles:

(2) Installing a Windows OS

I won't go into details into this. My assumption here is that if you're reading this, you know how to install Windows.


  • For this scenario, you're installing windows on the first partition (/dev/sda1).
  • Installing Windows will overwrite any existing boot loaders on the MBR. There is no way to prevent this.
  • It is advised to install Windows first, but when you're finished with this tutorial, the order really doesn't matter, but it is still most efficient.

(3) Installing Ubuntu Linux

Install your favourite flavour of Linux (Hopefully Ubuntu!).

Again, going into details on this is out of scope for this tutorial. If you need help with this, please see


  • You're installing Linux on the third partition (/dev/sda3).
  • If this is your first time configuring the "master boot" configuration, just leave all boot loader defaults from Linux's perspective.

(4) Configuring the "Master Boot Loader" for the First Time

There are two ways to do this:

  1. Legacy Grub

  2. Grub2

(i) Boot Master using Legacy Grub

  1. Boot a Ubuntu Live CD.
  2. Purging Grub2
    If this Ubuntu Live CD is version 9.10 or greater, it will come with Grub2 by default, so we need to purge it. If you're booting an older version of Ubuntu Live CD, skip ahead to Step #3.

    • Purge Grub2 from the LiveCD in-memory boot:
      sudo aptitude purge grub2 grub-pc
    • Install Legacy Grub:
      sudo aptitude install grub
  3. Mounting the "Boot Master" partition.
    sudo mkdir -p /mnt/boot_master
    sudo mount /dev/sda2 /mnt/boot_master
  4. Installing Legacy Grub files to the boot master

    Now, we want the boot master to be the first boot loader after POST. So, we'll install the grub files using the main HDD device. In this case, it's /dev/sda, but of course you should replace this as appropriate.

    sudo grub-install --root-directory=/mnt/boot_master /dev/sda
  5. Inserting a useful "Boot Master" menu.lst

    Here's a bit of a hack. I'm not sure how to automatically generate this file, so I'm just going to provide the one I've constructed for this scenario. You'll have to modify accordingly to fit your own configuration. (Come to think of it, it's probably better we don't try to automatically generate this file because it's completely custom for your installation.) I've stripped it down to the important text:

    # menu.lst - See: grub(8), info grub, update-grub(8)
    #            grub-install(8), grub-floppy(8),
    #            grub-md5-crypt, /usr/share/doc/grub
    #            and /usr/share/doc/grub-doc/.
    ## default num
    # Set the default entry to the entry number NUM. Numbering starts from 0, and
    # the entry number 0 is the default if the command is not used.
    # You can specify 'saved' instead of a number. In this case, the default entry
    # is the entry saved with the command 'savedefault'.
    # WARNING: If you are using dmraid do not use 'savedefault' or your
    # array will desync and will not let you boot your system.
    default         1
    ## timeout sec
    # Set a timeout, in SEC seconds, before automatically booting the default entry
    # (normally the first entry defined).
    timeout         3
    ## hiddenmenu
    # Hides the menu by default (press ESC to see the menu)
    # Pretty colours
    color cyan/blue white/blue
    ## password ['--md5'] passwd
    # If used in the first section of a menu file, disable all interactive editing
    # control (menu entry editor and command-line)  and entries protected by the
    # command 'lock'
    # e.g. password topsecret
    #      password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
    # password topsecret
    # Divider
    title           Operating Systems:
    # Ubuntu Linux
    title           Ubuntu 9.04 Jaunty Jackalope
    root            (hd0,2)
    chainloader     +1
    # Windows
    title           Windows 7 Ultimate
    rootnoverify    (hd0,0)
    chainloader     +1
    • default = 1 --> Our default OS will be Ubuntu Linux

    • timeout = 3 --> This is the master boot loader, there should be some timeout so that the user can choose the OS when desired. The "child" boot loaders could have a timeout of 0.

    • #hiddenmenu --> We want this menu to be visible, but the "child" boot loaders could have their menus hidden.

    • colors --> Pretty colours! (Grub2 can show this up)

  6. Installing Legacy Grub to the MBR I'm not 100% confident that in Step #4 this was already done, so let's ensure it's there manually: Enter the grub configuration tool
    $ sudo grub
    Find any legacy grub files on any partitions grub can find. You should expect to see the boot_master partition as at least one (or maybe the only) result. Make sure it makes sense!
    grub> find /boot/grub/stage1
    Tell grub where to point itself to, this is the boot_master
    grub> root (hd0,1) 
    Install grub to the MBR of the first hard drive, pointing to "root", (hd0,1), "boot_master".
    grub> setup (hd0)

(ii) Boot Master using Grub2

Most Linux distributions are now using Grub2 as their default boot loaders. While it is still possible to use legacy grub, you may choose to use the newer grub2 boot loader for your "Master Boot Loader".

  1. Install grub2 to the master boot partition, and no the master boot loader of the disk. Read: In our example, this results in something like:

    sudo mkdir /mnt/master_boot
    sudo mount /dev/sda2 /mnt/master_boot
    sudo grub-install --boot-directory=/mnt/master_boot/boot /dev/sda
  2. By default, a grub.cfg (menus) may not be automatically created. Let's create one, allowing grub to scan your system for operating systems and generate a default one:
    sudo grub-mkconfig -o /mnt/master_boot/boot/grub/grub.cfg
  3. Now edit the menus as necessary
    sudo vi /mnt/master_boot/boot/grub/grub.cfg

End of Scenario

There you have it! You've got a "Master Boot" boot loader chainloading any OS of your choice. Add an OS? -- add an entry in menu.lst. Remove an OS? -- remove that entry. Fully controllable.

Hopefully after reviewing the necessary steps for this simple scenario, one should be able to apply this to any multi-boot configuration.

Repairing the Master Boot Loader

Repair "Master Boot" Boot Loader w/ Legacy Grub

Did the installation of some OS wipe out the MBR pointer to your master boot loader? Let's re-use the procedures from the above scenario, simply follow these steps:

  1. Simplified Scenario --> Step #4, (i), (1-3)

  2. Simplified Scenario --> Step #4, (i), (6)

Repair "Master Boot" Boot Loader w/ Grub2


Re-installing Operating Systems

Now, you might be wondering, what if something didn't work, or if we re-install an operating system? Here are the brief instructions on how to "repair" any damage that any OS installation might do.


The installation of (any?) Windows will overwrite the MBR pointer to our boot master, so we need to simply repair it.

Follow: MasterBootLoader#Repairing%20the%20Master%20Boot%20Loader


During the installation of most Linux distributions, we can control how it installs a boot loader. Depending on the distribution, you [I]should[/I] be able to

  1. Install the boot loader to the MBR (default) -- not what we want.
  2. Install the boot loader to the [I]installation partition[/I].
  3. Don't install any boot loader at all.

If you do (b), you'll need to take no action with the master boot loader, it won't have been affected, and everything will just work! (Nice eh?) -- if you forgot to do this, or the particular Linux distro doesn't support it, simply follow: MasterBootLoader#Repairing%20the%20Master%20Boot%20Loader






MasterBootLoader (last edited 2013-08-22 01:49:26 by fermulator)