Configuring GRUB2 on Ubuntu to boot from another Linux partition

My recent Ubuntu installation was my first experience with the new GRUB 2.x series of bootloaders. Unforunately, the process of manually configuring GRUB2 on Ubuntu is not well documented in the case that everything doesn’t work “automagically.” I had to solve two problems: the blank screen at boot, and getting GRUB to boot to an existing partition with CentOS 5 installed.

Blank screen at boot

I got a blank screen after selecting an OS from the GRUB menu. GRUB seemed to work fine: it presented a menu of OS selections and allowed me to select one. Some text would then scroll by quickly, and then the monitor would then go blank and go into power-saving mode. This PC has an old NVIDIA card (I did not install any NVIDIA drivers). I found that I need to edit the file /etc/default/grub and set the nomodeset option:

GRUB_CMDLINE_LINUX="nomodeset"

I then ran the command update-grub to create the file /boot/grub/grub.cfg. You don’t want to edit this file by hand, since it gets over-written by configuration scripts.

Booting CentOS from GRUB2

Number  Start   End     Size    Type     File system     Flags
 1      80.0GB  160GB   80.0GB  primary  ext3
 2      32.3kB  107MB   107MB   primary  ext2            boot
 3      107MB   3183MB  3076MB  primary  linux-swap(v1)
 4      3183MB  80.0GB  76.8GB  primary  ext4

This PC had an existing hard drive partition (sda1) with CentOS 5.9, and I want to be able to boot either distribution of Linux. CentOS and Ubuntu are sharing the same boot (sda2) and swap (sda3) partitions. GRUB2 attempts to auto-detect existing operating systems and add them to the boot menu, but it does this in a very stupid way. Go back to /etc/default/grub and add the lines:

# Disable auto-detection of other OSes
GRUB_DISABLE_OS_PROBER=true

Re-run update-grub. Now you will need to manually create a correct entry for the CentOS partition. Since /boot/grub/grub.cfg is over-written on a regular basis, you need to add the boot entry to the file /etc/grub.d/40_custom. I added the following lines:

menuentry "CentOS (2.6.18-348.6.1.el5.centos.plus)" {
        linux /vmlinuz-2.6.18-348.6.1.el5.centos.plus root=/dev/sda1
        initrd /initrd-2.6.18-348.6.1.el5.centos.plus.img
}

Now, I can boot either distribution of Linux. I think it’s cool that they can share the boot and swap partitions!

One thought on “Configuring GRUB2 on Ubuntu to boot from another Linux partition

  1. Pingback: Bootloaders? | Dual Booted

Leave a Reply