Chainloading from one grub to another

If you install two (or more) Linux distributions on one machine, then by default they both install grub to the master boot record (MBR). The second distribution’s grub menu therefore overwrites the first.

For example, on my laptop, I have Windows on /dev/sda2, Fedora 8 on /dev/sda5 and Debian 4.0 (etch) on /dev/sda7. Having installed them in that order, I ended up with Debian’s grub menu, allowing me to boot into Debian or Windows.

It’s tempting to copy all the Fedora grub entries into Debian’s grub menu file to regain access to Fedora, but if the Fedora kernel gets updated, you have to manually update the Debian grub menu file to include the new Fedora entries. Fortunately, there is a better way: have two grub installations, and allow them to chainload each other.

The idea is to install each distribution’s grub into the boot record of its own partition, in addition to also having grub installed in the MBR (this is the one that you see first when the machine is switched on). The reconfiguration can all be done by booting into one distribution (because you can access the other distribution’s grub menu file by mounting its partition from the distribution you boot into). I booted into Debian and setup Fedora first:

grub> root (hd0,4)
 Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0,4)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0,4)"... failed (this is not fatal)
 Running "embed /boot/grub/e2fs_stage1_5 (hd0,4)"... failed (this is not fatal)
 Running "install /boot/grub/stage1 (hd0,4) /boot/grub/stage2 p /boot/grub/grub.conf "... succeeded
Done.

Then Debian:

grub> root (hd0,6)
 Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0,6)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0,6)"... failed (this is not fatal)
 Running "embed /boot/grub/e2fs_stage1_5 (hd0,6)"... failed (this is not fatal)
 Running "install /boot/grub/stage1 (hd0,6) /boot/grub/stage2 p /boot/grub/grub.conf "... succeeded
Done.

If you want to change the “main” grub menu (the one that comes up when you first switch on the machine), you can do that too. Notice that this time grub gets installed to the MBR due to the (hd0):

grub> root (hd0,4)
 Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  16 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,4)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
Done.

Now you need to add the appropriate entries to each distribution’s grub menu file. For Fedora edit /boot/grub/grub.conf:

title Debian grub
    root (hd0,6)
    chainloader +1

For Debian, edit /boot/grub/menu.lst:

title           Fedora grub
root            (hd0,4)
chainloader     +1

Now I get a “Debian grub” option in the Fedora grub menu, and a “Fedora grub” option in the Debian grub menu. Whenever I update either distribution, any new grub entries are added to the appropriate grub menu and I don’t need to tinker with the menu files.

Advertisements
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

3 Responses to Chainloading from one grub to another

  1. Bryant says:

    I have 3 OS’s on an old Dell desktop (WinXP, Fedora8, Suse11) installed in that order. After doing this, as you mentioned in your article, my Suse grub has all three boot options. When I choose to boot into Fedora another grub loads with the same options (except Suse11 won’t chainload). I would actually prefer NOT to have one grub boot into another grub. Is it possible to configure things so only ONE grub will be displayed and if so how?

    Thanks ahead of time for your assistance with this.

    Bryant
    hardyb@gmail.com

  2. richardfearn says:

    @Bryant: Do you mean you just want the entries you see in the first grub menu to go straight into each operating system instead of into another grub? If so you just need to copy the “real” OS entries from the other grub menu files into the main one, and remove the entries for loading other grub instances.

    If choosing Fedora takes you to the same grub instance with the same entries, it might be that the partition isn’t set correctly for the Fedora grub. Try editing the Fedora entry (select it and press ‘e’) and change the partition to see if you can get it to appear. Of course, that assumes you did install Fedora grub to the Fedora partition (since it usually goes to the MBR).

  3. Pingback: Chain Loading New GrUB From Old GrUB | Wills' World

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s