Troubleshooters.Com, T.C Linux Library and Grub Grotto Present

Making a Dedicated Grub Partition

Copyright (C) 2006 by Steve Litt, All rights reserved. Material provided as-is, use at your own risk. 

Steve Litt is the author of the Universal Troubleshooting Process Courseware,
which can be presented either by Steve or by your own trainers.

He is also the author of Troubleshooting Techniques of the Successful Technologist,
Rapid Learning: Secret Weapon of the Successful Technologist, and Samba Unleashed.



This document contains a series of exercises accessing, and in some cases overwriting, your boot loader. There's a significant possibility of overwriting your existing boot loader, which can lead to lost time and even lost data. There may be other risks.

You use this document at your own risk. I am not responsible for any damage or injury caused by your use of this document, or caused by errors and/or omissions in this document. If that's not acceptable to you, you may not use this document. By using this document you are accepting this disclaimer.


I'm not a Windows authority. I stopped buying commercial software in 1999, therefore never upgrading Windows past Win98 version 1. My knowledge of Win2K and WinXP is that of an occasional user (at somebody else's office). Therefore, I cannot tell you how to dual boot Windows.


It's absolutely essential you undertand the contents of Grub From the Ground Up before attempting anything on this page!

Why Dedicated?

If you've ever had four or more Linux distros on one box, you already know the answer. Install a new distro, and you lose the ability to boot the others. Oh sure, some distros are nice enough to try to detect the others, but often label them wrong. Some distros don't even try, but assume they're the only distro on the disk. Some distros overwrite everything with LILO.

When installing, removing and tweaking multiple distros on a single box, what you really need is a single menu of all boots. Ideally, you don't want that menu associated with a distro, because it it were, it would be overwritten every time you remove or reinstall that distro.

This document walks you through creating a 1 MB hard disk partition containing the grub boot code and the grub menu for all your various boots. By keeping this one and only one menu up to date, you avoid the confusion of constantly having to re-import all other boots every time you install something new. Because the partition is only a single megabyte, you avoid the temptation to cannibalize it for something else.

Once your grub partition is in place, adding a distro is as simple as installing that distro, then mounting the grub partition, and adding the new distro's grub boot information (menu.lst) to the boot distro's menu.lst, and then resetting the hard disk MBR to point to the grub partition.

Creating Your Grub Partition

Unless you have very strange hardware with special booting needs, you can fit all Grub code into a 1MB partition. Create the partition with fdisk. The fdisk program is able to make tiny partitions not on cylinder boundaries. Other programs such as cfdisk round to the nearest cylinder boundary, thereby making this partition much bigger than it needs to be. For the same reason, use fdisk to create the partition after this one, to make sure that no space is left in the middle. From then on, assuming partitions are big, other partitioning programs are fine, because a few megabytes on one side or the other of a 2GB partition aren't significant.

If you're working with a very old bios with the ancient 1024 cylinder limitation, it should be very near the front of the disk (make it /dev/hda1). Remember, it's only a megabyte in size, so it's not going to "push out" any other partitions with this limitation (typically the /boot partition). As a practical matter, modern bios implementations don't have this limitation, so on modern machines you can put the grub partition anywhere.

Try to make sure to remember the device number (/dev/hda1) or whatever) housing the grub partition. However, if worst comes to worst, you can quickly see which partition using this command:
fdisk -lu /dev/hda
The preceding command prints out the number of sectors used by each partition. The Grub partition will be the smallest, because no modern operating system can be housed in a 1MB partition.

Once you've used fdisk to create the partition, format it with the mkfs.ext2 command. There's no use making this an ext3 partition, because it's small enough to fsck anyway.

Setting Up Your Grub Partition

This is simply a matter of copying files. At the very least, you must have these three files:
  1. stage1
  2. stage2
  3. menu.lst
You can copy stage1 and stage2 from the /boot/grub directory of the booted OS, or any partition. However, if you have any unusual hardware or journaling file systems besides ext3, you'll need some of the "stage1_5" files. In such a case, ALL the stage files must be copied from the same source. On your currently booted distro, perform the following command:
locate stage
Here are some of the files that command shows on my Mandriva 2006 system:
I could copy ALL those files to the grub partition, or just stage1 and stage2.

Here's how I'd do it:
mkdir /mnt/test
mount /dev/hda1 /mnt/test
mkdir -p /mnt/test/boot/grub
cp -p /lib/grub/i386-mandriva/* /mnt/test/boot/grub
Note that on my system, a du command reveals that all those files consume only 376KB, so there's plenty of room.

The only thing left to do is create /mnt/test/boot/grub/menu.lst.

Making Your menu.lst

If possible, find a partition whose menu.lst contains choices for booting several different partitions. If the partition having such a menu.lst were /dev/hda7 and your Grub partition were /dev/hda1, and you mounted them as /mnt/hda1 and  /mnt/hda7, you'd perform the following command:
cp /mnt/hda7/boot/grub/menu.lst /mnt/hda1/boot/grub
Now that you have a starter for menu.lst, edit the file and pull in the info from menu.lst files from other partitions, straight into your editor. In each case, delete out the new global information and keep only the info for each new boot. Be careful that you don't get two different choices for essentially the same boot.

Occasionally, on LILO-only distributions, you might find no menu.lst file. In that case, import that distro's /etc/lilo.conf and translate LILO menu info to Grub menu info. It's not difficult if you do it slowly.

As you edit the file, make different versions so that if it doesn't work you can try a simpler version.

Making it Happen at Boot Time

You've made your menu.lst on your Grub partition, complete with boot info from every distro on the system. The trouble is, that menu file won't be consulted at boot time. To get the boot to consult it, you need to tell the hard disk's MBR to consult your Grub partition. Assuming your Grub partition is /dev/hda1, here's how you do it:
# grub
grub> root (hd0,0)
grub> setup (hd0)
grub> quit
# reboot
In the preceding command sequence, the first runs the grub executable. The second sets the root to (hd0,0), which is grub-speak for /dev/hda1. The third command tells grub to install code on the MBR that looks to /dev/hda1 for boot code. The fourth command terminates the grub command, and the fifth reboots the computer. When the computer reboots, if all went well you should see the menu you set up on your grub partition. If not, troubleshoot. If need be, bust back into the machine using the Grub techniques on the Grub From the Ground Up page, using either a Grub floppy or a Knoppix CD.

Adding a New Distro

This is where you start to see the real benefit of the dedicated Grub partition. In the bad old days, installing one more distro on your hard disk would necessitate a long and difficult search for other boots, culminating in voluminous troubleshooting. Now you simply edit your Grub partition's menu.lst and add the boots (not the globals) from the latest distro addition. Booted into the latest distro, signed in as root, it would go something like this:
  1. Mount /dev/hda1 /mnt/test
  2. cd /mnt/test/boot/grub
  3. cp -p menu.lst menu.lst.bup
  4. vim menu.lst
  5. Within vim:
    1. G  to get to the bottom
    2. o <Enter><Enter><Enter><Enter> (in order to open a space)
    3. :r /boot/grub/menu.lst
      1. NOTE: If the new version had /etc/lilo.conf and no /boot/grub/menu.lst, you might need to read in lilo.conf and then translate. It's not particularly difficult.
    4. Delete all global info brought in by the new menu.lst, and also any boots you don't need.
    5. :wq
  6. Run Grub, and within Grub do this:
    1. grub> root (hd0,0)
    2. setup (hd0)
  7. Reboot the computer, and your list should include all old boots as well as those brought in by the new boots.

The Case for Doing this On Every Hard Disk

A tiny dedicated Grub partition makes it easy to include a dedicated Knoppix partition, along with anything else you might need on the hard drive.

I find life much easier with a Knoppix partition on every hard disk I own. On dedicated data drives, it allows me to grab my data if my system drive should become defunct. It allows easy transfer of data between an old data disk and its replacement, either with the old disk still in the production computer and the new disk in a spare computer, or the new disk in the production computer and the old disk in the spare computer (in other words, you forgot to do it before shutting down the production computer with the old disk -- it happens).

You never know when somebody, some time, will dual or tri-boot the system. Or install six different OS's on it. Having a dedicated Grub partition makes such events much easier to handle.

Back to Troubleshooters.Com * Back to Linux Library * Back to Grub Grotto