If you are like me, you would want to have the option of booting your computer in more than one OS. While the virtualization domain can answer certain of the requirements, here today we will discuss some old school..
Objective: Want to dual boot my laptop between Ubuntu and Fedora. (This will work for Windows as well, incase you want to dual boot between Windows and Fedora).
Story: First I installed Ubuntu 10.04. It worked fine. I created 3 disk devices for it /dev/sda1 for /root partition, /dev/sda5 for /boot partition and /dev/sda7 for /home partition. This means the grub bootloader got installed in its default location /boot/grub/grub.cfg file ie on /dev/sda5. The total of all the Ubuntu partitions being 50 GB.
Next, I installed Fedora 12 on the remaining free space on my hard disk (70 GB).
I created the disk layout as the default LV (Logical Volume) to fill that 70 GB. The installation went smoothly otherwise.
Problem:
While both Ubuntu and Fedora installed smoothly individually, the latter Fedora install overwrote the Ubuntu Grub bootloader with its own. This happened because, during the Fedora Install, the Anaconda installer did not detect my existing Ubuntu installation. So it installed its own version of Grub on top of the MBR (master boot record). Isn't that strange? You would expect one flavor of Linux to work with another flavor of Linux. But no, reality is different.
This means each time I boot my computer, it does not display the bootloader menu giving me the option of choosing which OS I want to boot. Instead it boots Fedora directly. So my challenge is to rectify the bootloader to show both the Ubuntu and Fedora menu options.
Solution:
Since a computer with one single disk can have only one Master Boot Record (MBR - the first 512 bytes of the primary disk, that the bootloader reads when booting a system), this means the MBR can point to only one grub bootloader -- either the grub written by Ubuntu or the grub written by Fedora. I chose the Fedora grub file as the primary grub for my system (just a personal preference). Now, if I can somehow link Fedora's grub file to sense and read the Ubuntu kernel linux, I will be able to dual boot as required. For this I proceeded like this.
1-Boot system in Fedora.
2-After booting, open a terminal window (Applications > System Tools > Terminal)
3-su to root.
4-As root, run fdisk -l to list the partitions on the system:
[root@Time-Machine ~]# fdisk -l | head -15
Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xf8000000
Device Boot Start End Blocks Id System
/dev/sda1 1 2432 19530752 83 Linux
/dev/sda2 2432 6079 29294593 5 Extended
/dev/sda3 * 6079 6105 204800 83 Linux
/dev/sda4 6105 14593 68185088 8e Linux LVM
/dev/sda5 2432 3040 4881408 83 Linux
/dev/sda6 3040 3648 4881408 82 Linux swap / Solaris
/dev/sda7 3648 6079 19529728 83 Linux
In the above, /dev/sda3 is the location of Fedora boot partition (indicated by *).
It also shows that /dev/sda1, /dev/sda5, /dev/sda7 (the three Ubuntu partitions as discussed above).
5-Mount the Ubuntu boot device (in this case /dev/sda5, as noted in the beginning of this blog).
[root@Time-Machine ~]# mount /dev/sda5 /mnt
[root@Time-Machine grub]# cd /mnt/grub
[root@Time-Machine grub]# vim grub.cfg
...
<<< go to the section that shows the boot menu entries like below >>
...
menuentry 'Ubuntu, with Linux 2.6.32-21-generic' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,5)'
search --no-floppy --fs-uuid --set a2c4413e-051a-4479-bf86-403e4e115378
linux /vmlinuz-2.6.32-21-generic root=UUID=cf4be790-27f7-4c7a-a61b-0a326de514fc ro quiet splash
initrd /initrd.img-2.6.32-21-generic
}
6-Copy the above lines in a temporary file like temp.txt
7-Then go to Fedora's /boot directory and open its grub.conf file.
[root@Time-Machine ~]# cd /boot/grub/
[root@Time-Machine ~]# vim grub.conf
...
<<< add the lines copied in step 6 above (ie from Ubuntu grub.cfg) and modify Fedora's grub.conf as shown in red below >>
...
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,2)
# kernel /vmlinuz-version ro root=/dev/mapper/vg_timemachine-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,2)/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.31.5-127.fc12.i686.PAE)
root (hd0,2)
kernel /vmlinuz-2.6.31.5-127.fc12.i686.PAE ro root=/dev/mapper/vg_timemachine-lv_root LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rhgb quiet
initrd /initramfs-2.6.31.5-127.fc12.i686.PAE.img
title Ubuntu with Linux 2.6.32-21-generic
root (hd0,4)
search --no-floppy --fs-uuid --set a2c4413e-051a-4479-bf86-403e4e115378
kernel /vmlinuz-2.6.32-21-generic root=UUID=cf4be790-27f7-4c7a-a61b-0a326de514fc ro quiet splash
initrd /initrd.img-2.6.32-21-generic
Note: Since this is the grub.conf created by Fedora, its syntax is slightly different from that of grub.cfg on Ubuntu. Example instead of 'menuentry' it is called 'title', instead of referring to the kernel as 'linux' it is called 'kernel'.
Note: Also that grub names each disk device starting from 0. so /dev/sda1 is (hd0,0), /dev/sda2 is (hd0,1) etc. This means /dev/sda5 (the /boot partition for Ubuntu in this case) is (hd0,4) in the 2nd line.
And Thats it. Now I saved the grub.conf and rebooted. And this time grub shows me the menu options for booting either Ubuntu or Fedora. So, everything works like a charm.
Have Fun. Linux is Fun.