Sometimes, despite how advanced desktop GNU/Linux has become, it's desirable to have your computer able to boot into Windows without the use of an emulator. If you had Windows pre-installed on the computer at the time you installed GNU/Linux, this dual-booting ability is added automatically on all modern distributions. However, if you want to install Windows after Linux, this seems like a complete headache. Not really! The process is easy.

This article is written while installing Windows 7 Beta on a PC with Mandriva Linux 2009 already installed. Of course, the same procedure – with some minor adjustments – applies with any Linux distribution and any Windows version!

Partitioning and Installing

I started off by re-partitioning my hard drive, without destroying the data on it. I used the Gnome Partition Editor, a very convenient tool (works just like Partition Magic) which can either be installed on your hard disk, or run off a live CD! This last feature is extra cool, if you happen to need an emergency partitioning scheme. I just shrunk my partitions and left a bunch of free space at the end of my hard disk. I then created an Extended Partition on this free space.

Installing Windows was a piece of cake. Unlike its predecessors, Windows Vista and Windows 7 ignore the existing non-Windows partitions and propose to install itself in the free space, naming the newly created volume as drive C:, which is what you'd expect anyway. Almost half an hour later, the system was installed.

Restoring the bootloader

At this point, Windows has overwritten the Master Boot Record with its own bootloader. This effectively means that we can't boot into Linux any more! This is an easy fix. Just pop your Mandriva boot CD / DVD in the drive and boot from it. At boot time you are presented with a menu. Just choose “Rescue mode”. Half a minute later, after the rescue system has finished loading, you'll be prompted with a text menu. Choose “Reinstall boot loader”. The rescue system will scan your hard drives for Mandriva installations and ask you to confirm that you want to re-install the boot loader. Just say yes. That's all!

Telling the bootloader how to load Windows

At this point, when you reboot, you will see that you are only able to boot into Linux. Hmm... We've got to tell the Linux bootloader (it's called GRUB – Grand Unified Bootloader) how to load Windows.

After logging in, open a console (gnome-terminal for Gnome users, konsole for KDE users) and become root, for example sith su.

We'll have to edit a configuration text file, /boot/grub/menu.lst. Based on which visual text editor is available on yoru system, you may want to try one of these:

gedit /boot/grub/menu.lst
kwrite /boot/grub/menu.lst
gvim /boot/grub/menu.lst

Now, before the line reading “title failsafe”, add the following:

title windows
root (hd0,2)
makeactive
chainloader +1

The only thing you might have to change is the “root (hd0,2)” line. The number after the comma determines the partition you want to boot from. If you had created an extended partition to install Windows into it, this number is probably correct. If you had created a logical partition, you might want to try other numbers. Remember that the first partition is 0 (i.e. hd0,0). I've found that the best way to figure out the correct number is try and error. Using an invalid number does no harm, it will only cause GRUB to throw an error while booting.

Back to the root console, issue this command:

/boot/grub/install.sh

This will re-install the boot loader with the updated settings. Reboot and try the new “Microsoft Windows” menu entry in the boot loader. If you got the correct partition number you should see Windows loading.

That's all folks! I hope you enjoyed it :D

No comments