Thursday, January 28, 2010

Recovering Ubuntu After Installing Windows


Few days ago i installed windows over already existing ubuntu , and then i was not able to boot into ubuntu.This was because the grub in MBR was over writtern by bootstrap loader.
So i searched every possibility and recoved my ubuntu.
The method that worked for me is......

Requirements:

 
UBUNTU LIVE CD (i used jaunty ya 9.04)

Method:

This method will overwrite your Master Boot Record. In order to boot Ubuntu we will be overwriting the Master Boot Record. This is to be expected and is part of this guide.

The Master Boot Record will then point to Grub as the initial bootloader. The Windows bootloader is contained within the Windows partition and will then be chainloaded by the Grub bootloader.

WARNING

Do not use Ubuntu 9.10 live CD to restore the boot loader from a previous version.

Ubuntu 9.10 (and later) uses Grub2, which differs considerably from Grub Legacy (the version of Grub used in Ubuntu 9.04 and earlier). Attempting this method with Grub2 will leave you in shell mode with no boot menu. If this happens, repeat the procedure with 9.04 or earlier (i.e. one that uses Grub Legacy). Installing Ubuntu 9.04 and updating it to 9.10 through the Update Manager does not upgrade Grub to Grub2.

The first step is to boot from a Live CD and open a terminal. You will need to run a few commands as root. One option is to first run sudo -i which will send you to a root shell from which you will simply run the commands without the sudo prefix. Be extremely careful when running a root shell, especially for typos! Even an extra space can do damage to your system. Always backup on external media before attempting recovery, if at all possible.

Next we will need to find the partition in which your Ubuntu system is installed. Type the command fdisk -l. It will output a list of all your partitions. Example :

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

In this example three Linux partitions are listed. /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 there.

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.

If, after installing grub, Windows does not appear in the boot menu, you will need to edit /boot/grub/menu.lst
Open a terminal and enter:


sudo gedit /boot/grub/menu.lst

Now enjoy with your dual boot ubuntu and windows.

0 comments: