Monday, November 29, 2010

How to edit grub files so Ubuntu boots after installing Fedora

Recently I installed Fedora 14 as a third OS, having Ubuntu 10.10 and Windows XP in other partitions. I told Fedora to install the grub loader, and now I had this in /boot/grub/grub.conf :

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,5)
#          kernel /boot/vmlinuz-version ro root=/dev/sdb6
#          initrd /boot/initrd-[generic-]version.img
#boot=/dev/sdb
default=0
timeout=5
splashimage=(hd0,5)/boot/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.35.6-48.fc14.i686)
    root (hd0,5)
    kernel /boot/vmlinuz-2.6.35.6-48.fc14.i686 ro root=UUID=e0a1c43c-0bc5-4762-b497-16f99a6e8bc8 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rhgb quiet
    initrd /boot/initramfs-2.6.35.6-48.fc14.i686.img
title Fedora (2.6.35.6-45.fc14.i686)
    root (hd0,5)
    kernel /boot/vmlinuz-2.6.35.6-45.fc14.i686 ro root=UUID=e0a1c43c-0bc5-4762-b497-16f99a6e8bc8 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rhgb quiet
    initrd /boot/initramfs-2.6.35.6-45.fc14.i686.img
title Ubuntu 
    rootnoverify (hd0,2)
    chainloader +1
title Windows XP
    rootnoverify (hd0,1)
    chainloader +1

 But when I tried to boot to my Ubuntu, it didn't work. This is how I solved it:


We will need to edit some files as root, the easiest way to do this, IMHO, is to open terminal and run
sudo nautilus
so we can browse everything as root and edit what we please, or
sudo gedit file_to_edit
to just edit a single file as root.
But Fedora does not allow you to "sudo" by default.


And if you try

su
nautilus
or
su
gedit


It doesn't work. (http://forums.fedoraforum.org/showthread.php?t=253687)
So let's add our user to the sudoers file.

Open a terminal, run
su
(enter password)
visudo
page-down to the bottom
press "insert" key to start editing, and add this line to the bottom:

laura ALL=(ALL) ALL

where "laura" is your username. Press esc, and then type
:wq
to save and exit. (A more complete guide for this can be found here: http://fedorasolved.org/post-install-solutions/sudo )

Ok now finally we can "sudo nautilus". We need to edit /boot/grub/grub.conf from our Fedora root partition.

We can comment the lines

#splashimage=(hd0,5)/boot/grub/splash.xpm.gz
#hiddenmenu

(by placing "#" in front) if we like. This is so the grub menu appears when booting without pressing any key, it is easier that way to reboot several times and always see the grub menu. You can uncomment it again later.

Now open a nautilus as a normal user, and make sure the partition where your ubuntu root resides is mounted. (Click its name if it doesn't have the "eject" arrow to the right) Now that mount will be visible from your root nautilus. (??? Why do we need to do this? it is a mystery: nautilus as root does not list all available disks or partitions like normal-user nautlus does).

(Here we see the root nautilus to the right, where the partition mounted as "127 GB Filesystem" in the normal-user nautilus, is shown as a long UUID).

Then open /boot/grub/grub.cfg, we will not edit this file, we'll just copy some lines from it to the fedora /boot/grub/grub.conf file.
It will contain something like this:

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then

[snip]


### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu, with Linux 2.6.35-23-generic' --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    insmod part_msdos
    insmod ext2
    set root='(hd0,msdos3)'
    search --no-floppy --fs-uuid --set 3089130e-0a2e-4f80-8eee-a3030a6810ea
    linux    /boot/vmlinuz-2.6.35-23-generic root=UUID=3089130e-0a2e-4f80-8eee-a3030a6810ea ro   quiet splash
    initrd    /boot/initrd.img-2.6.35-23-generic
}

[snip]

This is the part we are interested in:
linux    /boot/vmlinuz-2.6.35-23-generic root=UUID=3089130e-0a2e-4f80-8eee-a3030a6810ea ro   quiet splash
initrd   /boot/initrd.img-2.6.35-23-generic 



copy these lines to your Fedora /boot/grub/grub.conf and replace the word "linux" to "kernel". It should look like this now:

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,5)
#          kernel /boot/vmlinuz-version ro root=/dev/sdb6
#          initrd /boot/initrd-[generic-]version.img
#boot=/dev/sdb
default=0
timeout=5
#splashimage=(hd0,5)/boot/grub/splash.xpm.gz
#hiddenmenu
title Fedora (2.6.35.6-48.fc14.i686)
root (hd0,5)
kernel /boot/vmlinuz-2.6.35.6-48.fc14.i686 ro root=UUID=e0a1c43c-0bc5-4762-b497-16f99a6e8bc8 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rhgb quiet
initrd /boot/initramfs-2.6.35.6-48.fc14.i686.img
title Fedora (2.6.35.6-45.fc14.i686)
root (hd0,5)
kernel /boot/vmlinuz-2.6.35.6-45.fc14.i686 ro root=UUID=e0a1c43c-0bc5-4762-b497-16f99a6e8bc8 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rhgb quiet
initrd /boot/initramfs-2.6.35.6-45.fc14.i686.img
title Ubuntu 2.6.35-23-generic
root (hd0,2)
kernel /boot/vmlinuz-2.6.35-23-generic root=UUID=3089130e-0a2e-4f80-8eee-a3030a6810ea ro quiet splash
initrd /boot/initrd.img-2.6.35-23-generic
title Windows XP rootnoverify (hd0,1) chainloader +1

I marked with red the modified parts. After updating the Ubuntu Kernel, you need to modify this file again so you can boot Ubuntu using that new kernel. Well, that's all for today, hope this helped someone. If you know better ways to do this, your input is welcome in the comments. I read somewhere that it's better to install Ubuntu last, because it recognizes installed OSs better, but I haven't tested this.

6 comments:

Dread Knight said...

Not quite sure why anyone would bother installing Fedora :P

Txenoo said...

Another option that i think makes things easier is including in your Ubuntu Grub a reference in the Fedora Grub with the following command.


title UBUNTU 10.10
configfile (hd0,2)/grub/menu.lst

when you use this file option a secondary grub menu is opened with the Ubuntu configurations for booting. So if you update ubuntu it is updated in its configuration menu.lst and no need to change anything to make your Ubuntu bootable.

Rolandixor said...

O.o

luisbg said...

su -c "gedit"

James said...

Txenoo: A freshly installed Ubuntu 10.10 installation won't have a menu.lst file since it is running Grub 2, which has a different configuration file format.

That said, it should be possible to chain load grub2 from Fedora's boot loader with something like this:

title Ubuntu
root (hd0,2)
kernel /boot/grub/core.img

This shouldn't require any changes when installing Ubuntu kernel updates, since they will be picked up from the Grub 2 configuration file.

L. said...

@James: Still haven't tested your solution, but I will try and see what happens, and let you know. thanks! (I had to add a new kernel entry already, I'm ready to try something that saves me from it)