Friday, November 13, 2009

Grub does not load after making changes in partition table

You have installed Linux and your Operating Systems are loaded using GRUB. Now you made changes to your partition table. After restarting you see that your system just got messed up! Grub gives error in black screen and you just cannot enter into any OS! Whoa!! You might be thinking what you did!!




[I cannot ensure you that the error code in the image will match with yours.]

Well grub stores all information including its boot menu in a partition which is mounted normally in /boot. When you create a new partition, create a new logical drive or delete one the partition table changes which means the partition number for /boot changes. But GRUB still tries to boot from the previous partition which is not the desired one and it ends with a failure message.

Now that you know it’s a sily problem. So how do you let GRUB know the new partition number for /boot? You need to access the linux filesystem to do this. There are numerous ways you can do this though I’ll mention the easiest and interesting two.

Remember these methods only work if you haven’t deleted the boot partition. If you have changed the active primary partition either you must switch it back or install bootloader on the newly active partition too before proceeding this method. If you have deleted boot partition but you have Windows unaffected then you can use Windows CD/DVD to boot to a command prompt and fix the mbr.


Method 1: Using Ubuntu Live CD or Linux CD/DVD

For Ubuntu you have to add sudo before every command.
  • Boot from Fedora Core DVD/CD (any Linux CD/DVD will work)
     
  • Select rescue mode if there's no rescue mode then select text mode and type linux rescue then Enter
     
  • Skip media test
     
  • If asked to enable Network interface: select no
     
  • Click Next>Next..
     
  • If you are using Fedora Core DVD first give this command when the terminal appears.

    # chroot /mnt/sysimage

  • Then type these commands

    # fdisk -l


    Remember the partition number for for Linux partition.

    Now you need to change the boot partition number in GRUB Boot Menu.

How to edit GRUB Boot Menu

The boot menu for GRUB is stored in /boot/grub/menu.lst

If you are using Ubuntu Live CD or you have GUI then this command will work


# sudo gedit /boot/grub/menu.lst

But if only thing you have is the text mode terminal then apply this command to edit that file.

# vi /boot/grub/menu.lst

To insert texts press ‘i’ and then type texts you want to insert. To delete a character try using delete key first if it does not work then press ESC and then ‘x’.

To correct the partition number just change the line after "Title Fedora Core 8..."

There you wiil replace root (hd0, X) with the correct value of X that you remembered from the fdisk command. Reboot and eject the DVD/CD to boot from hard-disk. You should get your things back right then.

Boot without CDROM/DVD (for advanced users)

You can only try this if GRUB prompt comes just after starting your computer like this in image below.



Type in GRUB prompt like below:

GRUB> root (hd0, X) 

Here, hd0 means first hard disk,
X is any value
for example X=0 means C drive(1st primary partition c:),
X=1 (means 2nd primary partition)
X=4 (means D drive or partition after last primary partition)

After giving the commmand when you get this message "filesystem 0x83 or ext3" remember(or write down) the value of X which is needed when editing boot menu. Normal the Value of X is near to the value of previous one(before the change in partition table) like 1 or 2 less or added.


GRUB> cat /boot/grub/menu.lst

The boot menu configuration will be shown in output. It will help you to put correct command to boot the system.

Type the commands same as there after title "Fedora Core" except the
command root (hd0, X). You have to put the correct value of X as you got in prevous steps.

It will be like this:


GRUB> kernel /vmliuz-2.6.23.1-42.fc8 ro ........... 

Use tab for completion and accuracy.

Second command will be like this:


GRUB> initrd /initrd -****fcX.img 

* and X will be different for different versions

And finally type this command which will lead you.


GRUB> boot

The system will boot smoothly. After booting make changes to the file /boot/grub/menu.lst same way as described previously to keep the change permanent.

If you face a problem mention in comments.

No comments:

Post a Comment