Praveen's Blog

An Eternal Quest for Incremental Improvement

Reinstalling Windows On A Dual Boot Machine

Dual boot machines with Microsoft Windows and GNU/Linux is more widely seen in the Desktop PCs than a machine which is operated by GNU/Linux alone. Most of the newbies somehow manage to install GNU/Linux on their machine by stealing some space which is used by Windows. But, when it comes to reinstalling Windows again, they are dreaded like hell. The reason being that they think reinstalling Windows removes Linux from thier machine. I have seen a lot of posts to the local user groups on this topic. Recently one of my friends was scared to do anything with her Windows and the registry was corrupted and she needed to reinstall it and asking a forum for some suggestions. So, I thought that let me post an entry on my blog on this topic so that atleast some will find the answer straight away by a search. Well, Google always favours me!

The most common myth on a dual boot machine is that when Windows is reinstalled, Linux is removed from the machine. But the fact is that the data in the Linux partition is not at all touched unless you use the Linux partition for installation. Then, how does your Linux vanishes? It is not the Linux that vanishes but the boot loader program which is used to give you the boot selection option is removed from the MBR and the Window's boot loader goes to the MBR. This means that when you restore your boot loader program to the MBR again, you should be able to boot into Linux without any problem and ofcourse you will find your data untouched. There are two most widely used boot loaders on Linux. They are GRUB and LILO. GRUB has gone more popular these days over LILO. Here are the instructions for restoring your boot loader. Unless specified explictly, these instructions are common irrespective of the boot loader.

The first step is to boot into your existing Linux somehow. There is no explicit way of booting into your Linux since the boot loader is removed from the MBR. You need to get the help of a rescue disk. Most of the popular distribution's installation CD (CD #1) can be used as a rescue disk as well. For more details on this, boot with your installation CD and read the help on the boot prompt for options. I will deal with two major distributions, Fedora and Debian. You need to know which is the '/' partition of your Linux. If you know this already, then your job is simple. Otherwise, you need to use the installation CD and go to the rescue console with is usually in the tty2 to find out which is your '/' partition. I am not explaining it in detail as it is beyond the scope of the effort for this topic. Once you have found the '/' partition, you can proceed with booting your existing Linux.

In Fedora, insert the installation CD and type rescue in the boot prompt. This will boot the rescue kernel and drop you in a shell. At this time, your '/' is from RAMFS. You need to change it to your actual '/' partition. For doing this, issue the command chroot /dev/hda2 assuming that /dev/hda2 is your '/' partition. You will be now in your local Linux work area.

In Debian, insert the installation CD and type rescue root=/dev/hda2 assuming /dev/hda2 is your '/' partition. The rescue kernel will boot and drop you in the shell directly in your local Linux work area.

Now you are all set to rewrite the boot loader back to the MBR. If you are using LILO, then just enter the command /sbin/lilo to restore the LILO back to where it was already. If you are using GRUB, you need to specify the where to write the MBR. Assuming your MBR is /dev/hda, then issue the command /sbin/grub-install /dev/hda to restore your GRUB back to MBR. Note that you need not worry that you will overwrite the Windows boot loader and you will not be able to boot into your Windows. Actually, Windows boot loader is installed both in MBR and BR of the Windows' C: and you will not be in a problem as the boot loader in the BR of Windows' C: is still fine.

Now reboot your machine to see your boot loader back on the MBR. Happy dual booting!

PS: I am planning to cover how to find out your root partition and how to identify the boot loader you were using as a seperate one.


Comments