November 3, 2006
Reinstalling Windows In A Dual Boot System
If you've ever setup a dual boot system with Windows and Linux before, you know that you have to install Windows first. Then you install Linux, which will include a boot loader that will allow you to boot into either operating system. But what do you do if want to reinstall Windows when you're using a boot loader like lilo or grub?
If you just put in the Windows CD and do a fresh Windows reinstall it will take over the system, and require you to reinstall Linux again, even if there's no need. What happens is Windows writes over the Master Boot Record (MBR), the first 512 bytes of the hard drive. The MBR points to the partition to find the bootable operating system, and Windows points it to itself. To avoid this, you can save the MBR before you install Windows, and write it back after the install to resume using your dual boot system as usual.
I did this in Ubuntu, but it will work in any flavor of linux. On the command line, enter the following:
sudo dd if=/dev/hda of=/path/to/save/mbr.image count=1 bs=512
Substitute the path you want to save the MBR image and the correct device of your hard drive, which is probably hda. You've now saved a copy of your MBR from your dual boot system. At this point you should save MBR image to a USB drive or email it to yourself. Now go ahead and install Windows.
When the Windows installation is complete, you need to write back the original MBR. Boot into Linux with a knoppix disc and find your MRB image. From a terminal run the following:
dd if=/path/to/saved/mbr.image of=/dev/hda
Of course remember to sub in the path to your MBR image and the device name of your hard drive. That's it. Reboot and things should be back to normal.