Installing Windows XP After Fedora 9

Disclaimer.
This text describes, how I installed Windows XP after Fedora 9. This is not a how-to. That is more a description of my experience in solving this problem. If you are going to try the same using this text, I am not responsible for any of your actions. Be extremely careful, when you are working with partitions. You may easily loose all your data.

Tools Needed.
You will need a Windows Installation CD and your Linux disto-cd ( dvd ). Also you may need some Linux liveCD – in my case I had to use Mandriva 2008 Spring One LiveCD.

Actions.
Cleaning up my PC last time, I removed slow Mandriva and decided to switch back to Fedora. Also, I had in mind that soon I will have to start my final year project, which is going to be Windows-based. So, I left unpartitioned space on my HD to install Windows there later on. A week ago I found a piece of free time which I used to complete my PC maintenance. When I was asked to choose a partition for Windows, it appeared, that Windows installer could not create partition in unpartitioned space of my HD. It said, that it “Setup unable to create a partition – partition table is full”. I was surprised a lot, and I had to explore from another direction. Obviously, partition had to be created in Linux, to give a chance to dummy Windows installer to copy its proprietary files somewhere. I booted up my Linux back and started the show.
At first, I needed to know, which exact layout does my hard drive have.

[root@localhost ~]# fdisk -l

Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xaa74aa74

Device      Boot      Start         End     Blocks           Id   System
/dev/sda1   *              1         2168    17414428+   83  Linux
/dev/sda2             2169       15044    103426470   83  Linux
/dev/sda3           15045       15299    2048287+    82  Linux swap / Solaris

That shown me, that my HD is approximately half-used, and I have a lot of unpartitioned space after my existing partitions. Also, the output shows me that my HD name in the system is /dev/sda and I have 3 partitions, located in first 15299 cylinders. Also it says, that last cylinder has number 30401. Since I had read fdisk man page, I lost my trust to it – developers had written there: “fdisk is a buggy program that does fuzzy things – usually it happens to produce  reasonable results.”. That is why I remembered ( wrote down ) the range of free cylinders – in case if it will suggest me wrong ones. So, knowing where to place Windows partition, I did “fuzzy thing” using the “buggy program”.

[root@localhost ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 30401.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSes
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help):

Here was the tricky part. First time my sequence was:

n -> e -> 5 -> 15300 -> 30401 -> w     ( incorrect ).

After reboot partition /dev/sda4 appeared and it was marked as extended ( as expected ). I was sure that it is enough for Windows installer and rebooted into it. This time, installer created a partition, but it was unable to format it ( I didn’t format it under Linux ). When I tried to boot back to Linux, I got a nice message, saying “Error loading operating system”. After that I experienced many actions to recover my boot loader. At some point I was so desperate, that I thought, that installer had corrupted the whole file system. However, it was nothing more than a bug in my Fedora distro dvd – grub-install program didn’t work there. It didn’t work from Knoppix 5.1.1 either. But it worked from Mandriva liveCD. Also, I discovered strange fact about Knoppix – it loads successfully with approximate probability of 50%. Other times it crashes on different stages of loading.

After this epic fail I went deeper into manual pages and discovered, that Windows partition has to be not extended, but primary. Also it has to have a  special partition’s system ID, corresponding to vfat file system. So, correct sequence was:

n -> p -> 4 -> 15300 -> 30401
t -> 4 -> c -> w            ( correct ).

After reboot my partition table looked like this:

Device    Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        2168    17414428+  83  Linux
/dev/sda2            2169       15044   103426470   83  Linux
/dev/sda3           15045       15299     2048287+  82  Linux swap / Solaris
/dev/sda4           15300       30401   121306815    c  vfat

I reloaded into Windows installer and successfully formatted my partition into NTFS and installed my XP. Once installation was finished, I booted directly into Windows, using Windows boot loader. At this stage I had to choose, which boot loader to choose – GRUB, or Windows one. Fedora was and will always be my main OS, so I’ve chosen GRUB. To use GRUB, the one had to be installed under Linux. To install it, I had to boot into Linux. I could not boot to Fedora, so I booted into Mandriva One boot cd, and installed GRUB, using:

grub-install -root-directory=/media/hd /dev/sda1

Where /media/hd – is a mount point of my /dev/sda1 partition in liveCD’s file system. Perfect, now I could boot into Fedora, but I could not boot into XP – my Windows boot loader was overridden by GRUB. Windows boot loader bits had to be added into my /boot/grub/grub.conf file. In the end of the file I added:

title WindowsXP
root (hd0,3)
makeactive
chainloader +1

Where (hd0,3) was the number of my Windows partition ( 4th ), starting count from 0. At this point my partition table looked like:

Device    Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        2168    17414428+  83  Linux
/dev/sda2            2169       15044   103426470   83  Linux
/dev/sda3           15045       15299     2048287+  82  Linux swap / Solaris
/dev/sda4   *       15300       30401   121306815    7  HPFS/NTFS

Everything looked perfect. Two partitions with boot flag, boot sector points to GRUB, GRUB can chainload boot sector to point to Windows partition’s boot loader. Aim achieved.