Recover dual-boot Ubuntu - Making Windows Load GRUB (and then Linux)

Problem Situation: Let me call the 2 patitions A and B. A contains Windows xp sp2 and B contains Ubuntu 9.04. Windows got corrupt. I reinstalled windows in Partition A. Finally when i rebooted my computer, there was no option to access Ubuntu(partition B). Now i can work only from Windows. How could I recover Ubuntu?

Solution: 
This is taken from Dual-Boot Linux and Windows 2000/Windows XP with GRUB HOWTO.

Boot through Windows to insert Ubuntu Live CD and then restart your computer. Now automatically Ubuntu Live CD will bootup.

1. In Linux Live CD Interface open a command window.


2. Mount a drive which you can share with Windows. This could be a USB drive, a FAT32 partition on your hard drive, or if you are using a Linux distribution which supports NTFS writing natively (Such as Ubuntu 8.04 or later) then you can mount the actual Windows C:\ drive itself! The advantage of writing to the Windows drive is that you are going to need to put a file there eventually, so it saves time copying a file around. For example:
#mkdir /tmp/windows
#mount /dev/sda1 /tmp/windows

However, when writing directly to the C:\ drive you could also do some damage to the system if you delete or move something. If you do pick the option to write directly, go in, put the file where it belongs, and touch NOTHING else.

3. Now you are going to make a copy of your boot partition. Finding out what this is called is not always completely reliable since the Linux naming conventions differ from the GRUB naming conventions. Linux labels partitions as hd[Letter][Number] or sd[Letter][Number] whereas GRUB always names them as hd[Number][Number]. If you installed GRUB on (hd0,0), then the /boot partition will be on hda1 or sda1. (Since (hd1,0) == hdb1 or sdb1, then by extension if you installed GRUB on (hd0,1) then the /boot partition will be on hda2 or sda2 and so on and so forth.) This narrows you down to two possibilities. If you now paste ls /dev |grep hd it will let you know if you have that drive on your machine. If nothing comes up which matches, then that means you must have an sd drive.
Note: The command df won't work as you are booted from a Live CD.

4. Having determined your boot partition run this command as root:
#dd if=/dev/sda2 of=/tmp/windows/linux.bin bs=512 count=1
Looking at this example /dev/sda2 is your boot partition and /tmp/windows/ is the drive you want to copy the boot sector image to.

5. If you haven't created linux.bin in the Windows drive then you need to copy it there now.

6. Next, reboot your computer and boot into Windows. Open c:\boot.ini in Notepad, and add a new line at the bottom:
c:\linux.bin="Linux"

This file might be write protected. If that is so, you need to enable writing to the file. To do so, right click, and from the context menu select Properties. Then uncheck the box that says "File is read only". Make sure to put that checkmark back afterwards.
Next, make sure that at the top of the boot.ini file there is a timeout set, i.e timeout=5 or some such number.
Do not edit this file from the Live CD, even if you have NTFS write support. Linux and Windows represent line breaks in different ways, so even though you can edit the file, it won't add a new line.

7. That's it, reboot and you will be given the option of booting into Linux, selecting that will chainload GRUB and this will let you boot into your Linux distro.
Source: http://ubuntuforums.org/showpost.php?p=121355&postcount=5
Thanks

No comments:

Post a Comment