Fixing the grub error in Ubuntu
by sahab on May.27, 2010, under Ubuntu, ubuntu 10.04, Ubuntu 9.10
Installing Windows After Ubuntu
Normally when Windows is installed after Ubuntu the master boot record will be overwritten. This means that you would have to boot off a LiveCD and re-install grub. The steps are
#sudo grub
From the grub
Type
grub> find /boot/grub/stage1 (If you installed separate /boot partition, then find /grub/stage1 )
(hd0,1)
(hd0,5)
It dispay partition which contains your grub files. I have two linux OS installed.
Then run the following command
>root (hd0,1)
>setup (hd0)
(hd0) = the MBR for the hard disk which is where grub needs to install itself too for it to load on bootup.
Another Method
fdisk -l
Disk /dev/hda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot   Start     End   Blocks  Id System
/dev/sda1Â Â Â Â Â Â Â Â 1Â Â Â Â Â Â 8Â Â Â Â 64228+Â 83Â Linux
/dev/sda2Â Â Â Â Â Â Â Â 9Â Â Â Â 1224Â Â Â 9767520Â Â 83Â Linux
/dev/sda3Â Â *Â Â Â Â 1225Â Â Â Â 2440Â Â Â 9767520Â Â a5Â FreeBSD
/dev/sda4Â Â Â Â Â Â 2441Â Â Â Â 14593Â Â 97618972+Â Â 5Â Extended
/dev/sda5Â Â Â Â Â Â 14532Â Â Â Â 14593Â Â Â 498015Â Â 82Â Linux swap / Solaris
/dev/sda6Â Â Â Â Â Â 2441Â Â Â Â 14530Â Â 97112862Â Â 83Â Linux
Partition table entries are not in disk order
Here are listed three Linux partitions. /dev/sda2 is the root partition, /dev/sda1 is the /boot partition and /dev/sda6 is the /home partition. If you only have one partition, this means that your entire Ubuntu system is installed on that one.
Later there will be a section on how to determine which partition your Ubuntu installation is on if you have several different partitions.
First, create a mountpoint for your partition, for example:
mkdir /media/root
Then mount your partition in it. If you don’t know which one it is, then mount any of them, we will determine if it is the correct one.
mount /dev/sda2 /media/root
Replace /dev/sda2 with the correct name of your partition. To check if it is the correct one, run ls /media/root which should output something like this:
bin  dev   home    lib  mnt  root   srv usr
boot  etc   initrd   lib64 opt  sbin   sys var
cdrom initrd.img media proc selinux tmp vmlinuz
If what you have looks nothing like this, the drive you have selected is incorrect. Run umount /media/root in the Terminal to unmount it then mount and try another one. Should you have made a /boot partition you can mount it like so:
mount /dev/sda1 /media/root/boot
To make sure this is indeed the /boot partition, run ls /media/root/boot, which should output something like this :
config-2.6.18-3-686   initrd.img-2.6.18-3-686.bak System.map-2.6.18-3-686
grub           lost+found          vmlinuz-2.6.18-3-686
initrd.img-2.6.18-3-686Â memtest86+.bin
Once again, if what you have is not similar, unmount it and try another partition.
Now that everything is mounted, we just need to reinstall GRUB:
sudo grub-install –root-directory=/media/root /dev/sda
If you get BIOS warnings try:
sudo grub-install –root-directory=/media/root /dev/sda –recheck
Note: Replace /dev/sda with the location you want to install GRUB on. If all went well, you should see something like this:
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install’.
(hd0)Â Â /dev/sda
Reboot, making sure to boot to your hard drive and not to the live CD. Grub should be installed and both Ubuntu and Windows should have been automatically detected.
May 29th, 2010 on 7:16 am
Can I just say what a relief to find someone who actually knows what there talking about on the internet. You definitely know how to bring an issue to light and make it important. More people need to read this and understand this side of the story. I cant believe youre not more popular because you definitely have the gift.
May 29th, 2010 on 8:48 am
Please tell me it worked right? I dont want to sumit it again if i do not have to! Either the blog glitced out or i am an idiot, the second option doesnt surprise me lol. thanks for a great blog!
December 17th, 2010 on 4:54 pm
Stumbled upon your site, fantastic reading my friend!
January 19th, 2011 on 12:57 am
I am very thankful to this topic because it really gives great information ;,’
March 28th, 2011 on 7:00 pm
That is a great thread. It worked perfectly for me. You saved my neck
Thanx a lot.