Ever had the problem of not being able to boot Linux after fixing Windows?
This usually happens when you have to do a Windows re-install, but I have also had it after doing a hard reset when Windows crashes, and scandisk runs and "fixes" the boot sector. I've had to do this several times, but not for a while, so had to search LQ to find a fix the other day when my Mum's computer played up. I have migrated her to Linux, but needed to get at something on the old Win98 system, and of course it crashed while I was doing it. I thought it might be good to have an up-to-date fix here.
You will need either a Linux boot floppy (there are some good ones at
Slackware) or a bootable CD (a live CD). I use either
GParted, which can also help with partitioning and disk maintenance, or
RIP (Recovery Is Possible). You can also use CD 1 of the Suse install set (select Rescue from the boot menu). Most distro's with a live CD have a rescue option on the boot menu. I gather Ubuntu doesn't have it on the menu, but you can get it by typing "rescue" at the point where you enter boot parameters.
With one of the Slack boot floppies you can actually boot your existing Linux system. If you can do this go to Part 2 below.
If you can't boot your existing sytsem then you will need to use a live disk.
Part 1 - if you have booted a live CD.
Open a console window as
root, and mount your Linux root partition to a temporary directory.
Code:
#> mkdir /tmp/hdxx
#> mount /dev/hdxx /tmp/hdxx
/dev/hdxx is whichever partition is root for your Linux. For instance on this system it's
/dev/hda3. If you can write to
/mnt then you could use
/mnt/hdxx.
For
GRUB you will also need to do this:
Code:
#> mount --bind /dev /tmp/hdxx/dev
#> mount --bind /proc /tmp/hdxx/proc
#> chroot /tmp/hdxx /bin/bash
Part 2 - re-installing the bootloader
For
GRUB
Code:
#> grub-install /dev/hda
#> exit
...and reboot. Don't forget to take out the boot disk first!
For
LILO
You should see a list of bootable partitions.
... and reboot.
You should now have your boot menu back.
I also found some useful info about backing up the MBR
here.
There is also a
GRUB wiki, and
How to Set-up Grub by hand
Hope you find this useful, and thanks to all those who posted different versions of this around the web.