Monday, February 18, 2008

Forcing Windows to Install on the C: Drive

As a Windows administrator, I often find it necessary to re-install Windows. Thankfully, ever since Windows 2000, the number of times I have to format a computer has reduced drastically, however, every now and then, something goes wrong and nothing short of reinstalling the operating system will solve it.

Recently, my Windows XP x64 computer died on me. The problem seems to be hardware related and I have a sneaking suspicion that it is the memory, but I will leave the troubleshooting to the hardware guys at my local computer store since the system is still under warranty. However, my computer doesn't boot. So, I decided to reinstall Windows to fix whatever non-sense happened after the hardware failure.

After booting into the installation routine, I arrive at the partition section and guess what? - The Windows installation has decided to change around all my drive letters and looks something like this:

Drive 1:
Partition 1 - E: 80 GB
Partition 2 - C: 240 GB
Drive 2:
Partition 1 - D: 320 GB

Needless to say, it would be far better if my original installation drive (the E: drive) could be called the C: drive, as it was called in my original installation.

Now, if you google around, you'd find that everyone makes the suggestion of simply unplugging the drives before starting your installation so that Windows is forced to use the first drive letter it comes up with, namely, the C: drive. But we have a problem here. Partition 2 cannot simply be unplugged! It is a separate partition, not a separate drive, and cannot be unplugged without unplugging the partition we want to install on.

Prior to discovering this neat little trick that I'm about to share with you, I used to copy the files from the second partition of the primary drive to a backup disk, reformat and repartition the entire disk, then copy the files back. Needless to say, it wasy very time consuming. Now, before I continue, I would like to warn you right now that this solution is going to require a Linux Live CD, some patience and all your brains. With that in mind, let's begin.

Preparing the Linux Live CD:
The first thing we need to do is to get our hands on a copy of a Linux Live CD. If you already know how to do this, then by all means skip ahead to the next section, in which we modify the partition table and wherein contains the real contribution of this post.

For the uninitiated, Linux is an alternative operating system to Microsoft Windows and Apple's Mac OS X. It is free and supported by a community dedicated to the ideals of free computing. If you're interested in learning more about Linux, I suggest taking a look at Ubuntu, a relatively easy to learn Linux distribution. For our purposes however, we are going to download Knoppix. Knoppix, I find, has much better support for hardware than most other distributions. This is often important to me because I support a wide variety of hardware and I like it that my Live CD works well with all of them. That being said, you can download Knoppix here:

http://www.knoppix.org/

Once you get there, you should click download, pick a mirror and download the latest version. The file that you download is a CD image (.iso). You will need a CD burning tool to burn this image to a blank CD. There are many commercial applications such as Nero and Roxio that you can use to burn the ISO to a CD. If you need a free one, you can try InfraRecorder which you can download here:

http://infrarecorder.sourceforge.net/

Booting into Linux and Updating the Partition Table
At this point, you should have burned the Linux Live CD to some blank media. Pop this media into your broken computer and you should get the Knoppix prompt at bootup. This prompt is provided so that you can pass extra parameters to the operating system before it boots. In most cases, you wouldn't have to type anything here, so just hit enter. But, if you have trouble booting, or if you do need to pass extra parameters in order to get your system to boot, take a look at the Knoppix cheat codes here:

http://www.knoppix.net/wiki/Cheat_Codes

I, for one, have a large monitor and the resolution that Knoppix chooses for me is not a very good choice, so I usually pass the screen parameter so that I can achieve native resolution once I boot into Knoppix. The command I use is:

knoppix screen=1920x1200

Once you've booted into Knoppix, start the terminal which you will see an icon for at the bottom left of the screen. Before we modify the partition table, it is important to first unmount any harddrives that may have been automatically mounted by Knoppix.

$ mount

This will show you a list of mounted devices. Your windows partition will be called something like, /dev/sda1 or /dev/hda1 and it will be mounted in the folder /media. If you see any of these, you must unmount them before continuing:

$ sudo umount /media/sda1
$ sudo umount /media/sda2
$ sudo umount /media/sdb1

Now, double check that there are no further mounts and then start fdisk on your primary drive.

$ sudo fdisk /dev/sda

This will start fdisk. Type p [enter] to list the existing partitions. Now, what we want to do is hide the second partition from the Windows installer. To do this, type t [enter]. You will be prompted for which partition, type 2 [enter]. You will now be prompted for the Hex code. The Hex code represents the file system type described by the the partition table. Hit L [enter] to get a list of partition types. What you'll notice is that there are a very large number of partition types. The NTFS partition is represented by the code 07.

If you look right down at the end of the list, you'll notice that there's one called LANstep which is represented by the hex code fe. As it so happens, a long time ago when there were two flavours of Windows called, Windows NT and 3.1, Microsoft had used the code fe to administratively designate a partition that was not to be touched. Sound a little convenient? I thought so too. I learned about this fe code from the following site:

http://www.win.tue.nl/~aeb/partitions/partition_types-1.html

Which states quote:
fe Windows NT Disk Administrator hidden partition:

Mark Morgan Lloyd (markMLl.in@telemetry.co.uk) writes: Windows NT Disk Administrator marks hidden partitions (i.e. present but not to be accessed) as type 0xfe. A primary partition of this type is also used by IBM to hold an image of the "Reference Diskettes" on many of their machines, particularly newer PS/2 systems (at a rough guess, anything built after about 1994). This clash can cause major confusion and grief if running NT on IBM kit. When this Reference Partition is activated, it changes its type into 1 (FAT12) and hides all other partitions by adding 0x10 to the type.
Based on that quote, you should be careful if you're running this IBM kit. Assuming that none of this matters to you, go ahead and type fe [enter]. This will change the partition type of your second partition from NTFS to the administratively hidden NT partition. At this point, you're ready to save the changes you've made and then return to the Windows installer. In order to save your changes, type w [enter]. This will write the changes to your drive. Then you can quit fdisk by typing q [enter].

If you have other partitions that you would like to hide (say on a separate drive, etc) now would be the time to do it, by repeating the procedures described above. When you're finished hiding all your partitions, restart your computer, put the Windows installer back in the drive and then try to reinstall Windows. You'll find that the Windows installer detects the other partitions, but doesn't try to assign them a letter. This is good. Go ahead and install Windows on the 1st partition of your primary disk. You may be prompted about there being other operating systems and that by installing Windows, it may disrupt their operation. This is normal and you can safely ignore the warning.

When you're finished installing Windows, you'll notice that your other partitions are still hidden. You need to unhide these partitions in order to see them again. So, pop the Knoppix CD back in the drive and get back into fdisk. This time when asked for the hex code, use the value 07. This will flag the hidden partition as being a normal NTFS partition. When you restart back into Windows, your previously hidden partitions will become visible.

And voila! Your Windows is on C and you didn't have to repartition or reformat or even unplug your drives from the computer.

I hope this helps people who've had this problem in the past, however, I recommend that you back up your data before trying this for the first time. I cannot be held responsible for any loss of data that may be caused by following these procedures.