Make your own free website on Tripod.com

HOWTO:
Install Windows 2000/XP onto
a PC with Linux on it

21 February 2004 - Version 1.0

EQUIPMENT USED TO WRITE THIS TUTORIAL:

YOU WILL NEED:


PREAMBLE
Lots of people have detailed how to install Linux onto a PC that already has Windows on it, such as a new PC bought from a shop. Usually this is written from a Windows user's perspective.
        Nobody, AFAIK, has written about how to do it the other way around - how to install Windows onto a PC that currently has Linux dominating its hard disk, so that the two can live together in harmony. You might want to do this if, like me, your job means you have to work with Windows (even though you otherwise use Linux for everything else). This is actually not a trivial thing to do and requires knowledge of a couple of Microsoft Rescue console commands.
        So here's my guide to installing Windows on a primarily Linux-orientated machine. I use Red Hat/Fedora. Some of the commands I mention later might be Red Hat specific. I use GRUB for a bootloader too so if you use lilo, you'll have to have a read through the steps and do some of your own research (you'll have to learn how to rewrite the bootloader to the MBR and add an entry to its menu for Windows; info covering this is out there online).
        Before you start, be aware that the potential for damage is really incredibly high. Windows wants to gobble-up your hard disk. It will try to destroy Linux given half the chance - it has some Darwinian urge to wipe out the competition.
        Things can go wrong, especially with Microsoft programs. Windows is randomly catastrophic and lacks the predictability of its Linux cousin. Perhaps more importantly, just because this worked for me, it doesn't mean it's going to work for you. It could go horribly wrong. It probably will.
        YOU FOLLOW THESE INSTRUCTIONS AT YOUR OWN RISK! Backup your data first and, if in doubt, don't do it!

1) MAKE SPACE FOR WINDOWS ON YOUR HARD DISK
I'm assuming that your entire hard disk is taken up with Linux and you don't have any FAT32/NTFS partitions at all.
        First off, you need to free at least 5Gb or so in which to install Windows. Linux lacks a tool to repartition on the fly (I'm sure there's a Sourceforge project but, if there is, I wouldn't trust it with my valuable data until it's REALLY well established).
        You can use a proprietary program like Partition Magic to do the job although you'll have to make sure it understands Linux partition types. Only more recent versions of Partition Magic will deal with Ext3 and it's not clear if the likes of ReiserFS or XFS are supported. Check before splashing out for new software.
        The product info page for Partition Magic lists Windows as a system requirement but this is not fully correct. On version 8.0, which I have here, you can boot from the CD and run Partition Magic from there (this boots into Caldera DOS, supplied on the CD, so no Windows bits & pieces are needed at all). Using this version of Partition Magic is just like using the Windows program, complete with mouse operation.
        Alternatively you can just delete one of your Linux partitions. The obvious candidate on many Linux installs is the /home partition - move everything from there into your main Linux boot partition and blank it using Linux's fdisk (and remove the entry from fstab, of course). Or you could copy everything to the root partition, delete /home, and then recreate it but this time much smaller. It's up to you.
        FWIW I use cfdisk rather than fdisk - it uses a curses GUI interface which makes the whole procedure easier to follow, particularly when dealing with free space, although some people say that cfdisk isn't as reliable as fdisk.
        Note: don't try to make a FAT32/NTFS partition using Linux's fdisk or cfdisk. Windows won't recognise it. This task needs to be done under Windows itself. Talking of which...

2) MAKE A NEW PARTITION
Boot from your Windows CD. When the Windows pre-installation routine has finished loading every possible disk driver in the world ever, DON'T choose to install. Instead choose to boot to the Rescue console. When you get to the command prompt, type:

diskpart

This should give you a curses-style graphical display of the disk. Notice how your Linux partitions are unidentifiable by Windows but how it still gives them drive letters (!).
        You should spot the free space you created earlier. Use the cursor keys to move to it so it's highlighted. Hit C to create a new partition. You might get asked a few questions so answer them using common sense. Note how Windows will instantly rewrite the partition table without asking you to confirm it, or waiting until a later stage when you can confirm all your changes in one fell swoop. Make a note of the drive letter which Windows assigns to the new partition.
        Note: weird things can happen at this stage and this is where things are most likely to go catastrophically wrong. On my PC, I tried to create a new partition from all the available space (around 13Gb), and Windows instead split it into a 5Gb partition alongside 8Gb of free space. Without asking or telling me, of course. This might be something to do with FAT or NTFS limitations. In the end, to complete the next step of this tutorial, I chose the 5Gb partition to install into, which worked fine.

3) FORMATTING
After you've created your partition, quit out. I think you have to press F3 or something. You'll have to reboot so do so. At this point your boot sector will have been wiped so GRUB/lilo will be no more, and you'll find you can't boot into Linux. DON'T WORRY! We'll fix it later (hopefully).
        Boot from the Windows disk again and go to the Rescue console again. This time type

format {drive letter}: /FS:fat32

where "drive letter" is what you wrote down earlier. This will format the partition to FAT32. Both Win2K and XP can work under FAT32, even if Microsoft advises you use NTFS. Why choose FAT32? Well, it's natively supported in the kernel so you can mount it later under Linux and copy files to and from. NTFS support under Linux is VERY DODGY - you can usually read okay but writing to NTFS from Linux is not advised. (Note that FAT32 support is only in the kernel if it's been compiled into it - most distro kernels should provide support but if you've made your own kernel then, obviously, check your config file).
        When the formatting starts, you will see a message saying that it's going to format the "drive". It's not. It's just going to format the partition. Formatting will take a while depending on your partition size so go and make a cup of tea.


4) INSTALLING
When formatting has finished, type exit and reboot. Then boot from the Windows CD again. This time select to go for the full install and identify your brand spanking new Windows partition when prompted.
        There's no need to format it again, so select to use it as is. Then get on with installing Windows!

5) BACK TO THE WINDOWS CD...
At this point you can boot into Windows and use it normally - visit Windowsupdate, reboot, install your virus scanner, reboot, visit Windowsupdate again, reboot, install a firewall, reboot, visit Windowsupdate once more, reboot, and so on.
        However, we want to get back to Linux! But we've got to make sure the Windows partition will be bootable when we restore Linux to its rightful place as king of the hard disk.
        I know what you're thinking - how can we have just booted to Windows if it's not bootable? Well, Windows will have written a boot sector to the MBR and possibly not to its own partition. We're going to put GRUB onto the MBR. So we need to ensure there's a Windows boot sector onto the Windows partition so we can point GRUB at it later on.
        Luckily, this is easily done. But you're going to have to boot from that Windows CD again... Choose to go to the Rescue console and, when prompted, type in the partition number of your new Windows install. Enter the administrator password and, at the command prompt, type

fixboot {driveletter}: 

As you'll see from the on-screen prompt, this will install a bit of boot code onto the partition.

6) BACK TO LINUX
Almost there now...! Insert your Linux rescue disk (or CD-ROM) and boot. If you're using Red Hat or Fedora Core 1, you should automatically find your Linux partition mounted within /mnt/sysimage. Don't worry if you get a message that no Linux partition was found - sometimes it can be missed if it's in an extended partition. In this case just type:

mkdir /mnt/sysimage
mount /dev/hdax /mnt/sysimage
(Where x is the partition number of your Linux root partition - you can find this out by typing fdisk -l /dev/hda)
        Whatever the case, type chroot /mnt/sysimage to make the mounted file system into the root of your filesystem (this is necessary for the next step). Then switch to the sbin directory.
        You should find a program called grub-install, so use it as follows:
./grub-install /dev/hda

This will restore the GRUB bootloader program and menu.

7) BACK TO WIN2K/XP
But, but... you can now boot Linux but can no longer boot Win2K. Don't worry - the solution is simple.
        Boot into Linux and switch to root user. Edit your GRUB config file (in the following way if you're using Red Hat/Fedora):

vi /boot/grub/grub.conf 

        I'm not going to explain the ins and outs of grub.conf but, needless to say, you need to add an entry for your Windows partition. Here's what does the trick on my machine (I added this underneath the current entry for Linux):

title Windows 2000
root (hd0,1)
makeactive
chainloader +1


Have a read of the GRUB info file to learn more if need be.
        Note that you can experiment a bit within the GRUB bootloader itself if things don't work - highlight the entry at boot time and then hit e to edit the entry. Hit e again to edit any line you want, and then b too use it to boot.
        This can help if you're having trouble understanding exactly what numbering system GRUB likes to use to refer to your Windows partition (particularly problematic if, like me, you can't be bothered reading the GRUB manual and you're making use of an extended partition on the hard disk).
        Note: remember that the entries in the GRUB menu are case sensitive. GRUB will freak out if you type "Title Windows 2000", for example, rather than "title Windows 2000".

Hey presto! It should all work. If it doesn't then, well, quite frankly you're in trouble. Hopefully you should have either a working Windows or working Linux, from which you'll be able to go online and seek the help of others. Good luck.


APPENDIX

INSTALLING WINDOWS 98/Me: I tried to install Windows 98 but it was an "all or nothing" situation - it wouldn't install unless it could wipe my entire hard disk, thereby taking my ext3 partitions with it. There was no available option to select a partition into which to install. I lack a Windows Me disc so couldn't try this but I suspect it will be a similar situation.

BOOTING FROM CD: Only modern PCs can boot from CD. Normally this option has to be enabled in the computer's BIOS setup, which is accessed by press Del or one of the function keys during initial memory testing after the PC is turned on. Some modern PCs allow you to select at boot time which device to use so you can choose to boot from the CD/DVD drive.


(c) 2004 Keir Thomas (keir at soon dot com). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation. For more info, read the GNU Free Documentation Licence.

Coded using Mozilla Composer.


free hit counter