Multi-Booting with Legacy Grub and Grub2

When Ubuntu changed to Grub 2 a couple of releases ago, it became significantly more difficult to set up multi-boot Linux systems. Most if not all Ubuntu derivatives are also using Grub2, and now the latest Debian release also uses it.

When Ubuntu changed to Grub 2 a couple of releases ago, it became significantly more difficult to set up multi-boot Linux systems. Most if not all Ubuntu derivatives are also using Grub2, and now the latest Debian release also uses it. There are probably a lot of ways to set up multi-booting between these two; I will detail here what I do, which I think is reasonably simple and doesn't impose too many limits or inconveniences.

First, if you are willing to let a Grub2 system be the primary bootloader, everything will be pretty simple because the update-grub utility will generally figure out the other installed systems. But if you want a Legacy Grub system to be the primary bootloader, you'll have some work to do to get it to work with Grub2 partitions. The simplest solution that I have found is to install Grub2 to the root partition of the other installations, and then "chainload" from Legacy Grub to those, so Grub2 will still take care of actually booting them.

Of course, there are several routes that you might take to get to this final configuration, depending on what order you install the distributions. Let's suppose that you have a Grub2 system already installed (such as Ubuntu), and you want to install a Legacy Grub system (such as openSuSE) and set up multi-booting. What you need to do, before installing the new system, is set up Grub2 in the root partition of the existing installation. That is done with the command:

sudo grub-install --force /dev/sda1

You have to replace sda1 in this command with whatever your root partition might be. This will install the Grub2 bootloader, and will caution you that this is not a particularly good idea. Once this is done, you can go ahead and install the additional distribution, and let it install Legacy Grub to the MBR of the disk, thus making itself the primary bootloader. When that is done, you need to add three lines to /boot/grub/menu.lst:

title Ubuntu 10.10 root (hd0,0) chainloader +1

This again assumes that Ubuntu was already installed in /dev/sda1, so you might have to adjust the partition number to match your installation. Remember that Legacy Grub counts partitions from zero, so the number here will be one less than the /dev/sdaX number.

When you reboot after this, you will see Ubuntu in the boot menu, and if you select it the system will actually reload with the Grub2 bootloader, and you will get the Ubuntu boot menu.

If you start from the opposite end, with a Legacy Grub distribution already installed, the procedure is pretty much the same. In fact, when installing most Grub2 distributions you will usually have the opportunity to tell it to install the bootloader to the root partition rather than the MBR, but since this option is often buried in some obscure place, or it works in some way that I don't quite understand or expect, I always choose to just let it install itself normally and take over as the primary bootloader - it will see the existing Linux installation, and will add it to the Grub2 configuration. Once the installation is done, I log in and run grub-install as described above, then reboot again. When the boot menu comes up, this time I select the original (Legacy Grub) installation. I then login to that, edit the menu.lst file as desribed above to add the new Grub2 installation, and then restore Legacy Grub as the primary bootloader with these commands:

# grub root (hd0,2) setup (hd0)

Once again, this assumes that the Grub2 distribution is on /dev/sda3, you should adjust the partition number as necessary.

As I said at the beginning, this is just the way that I handle Grub co-existance. There are certainly other ways to do it, I pretty much figured this out on my own. It works pretty well for me, although it can get fouled up and require repair if another distribution is installed. If there are better, simpler or easier solutions, I would be happy to hear about it.

jw 26/3/2011