Home | eMail | Michael Dominok

Forking a XP-installation

Version en0.92 2005-01-24

0 Contents

0 - Contents
1 - Intro
2 - Scenario
3 - Setting Up XP
4 - Install Debian
5 - ntfsclone
6 - Modify NTFS-Bootsector
7 - Bootmanager grub
9 - Final steps

1 Intro

Back to contents

The idea is to copy (using ntfsclone) a fresh/clean XP-installation to two additional partitions on the same HD. The new ones should then get customised for special purposes like gaming or testing stuff. Then i'd like to create some images of these XP-clones so that i can easily reset them if^Wwhen they get messed up.
I got stuck two times trying to achieve this. The first time Anton Altaparmakov - a Linux NTFS Maintainer - gave me some good advice in the linux-ntfs.org-forum.
After being on the wrong track several times i found some very useful Information on Dan Goodells Website. In his excellent text: Understanding Multibooting
So i'm just summing up info here.

2 Scenario

Back to contents

In this scenario i'm using a single HD with a fresh/clean XP-installation on its first partition (about 20GB). This automatically cuts down the number of possible clones to two, since XP insists on being situated on a primary partition. The rest of the drive is used for an extended partition. One of its logical partitions will home a small Debian-installation. Well, in this example "small" is 30GB since it's to be used to store some XP-images later. The remaining space can be used for data-partitions or other operating systems with less affectatious demands than XP.

3 Setting Up XP

Back to contents

Another little nastiness with XP is that it "remembers" its surroundings. It doesn't only keep track of the systems hardware and moans if "too much" of it is altered but also stores data about the partitions it's "surrounded" by in its registry-key HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices This includes hidden partitions, too! If one simply clones such a XP and boots the new system, the environment stored in its registry doesn't fit the one it actually detects and XP gets "upset and confused". In my case login was still possible but followed immediately by automatic logout and system-freeze.
This can easily be circumvented by executing regedit and resetting/deleting the values in registry-key HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices
During its next reboot XP will then regenerate them according to its "new" environment, which, by then, will have been customised by us.

4 Install Debian

Back to contents

In this scenario the cloning will be done using Debian Linux. There sure are plenty of other ways to accomplish this. E.a. with proprietary Software or other Linux-distributions. I choose Debian for it's easy to install, the installation only takes a few minutes and - most important - for the simple fact that Debian rocks! Amongst other means of installations there's a Netinst-Image available. If you don't have a reasonably fast Internet-connection Just boot it and follow standard procedures until partitioning comes up. In case of problems you can consult Debian GNU/Linux Installation Guide
Whilst partitioning 2 primary ones should be created for the clones and marked "Do not Use" for Debian. Naturally it's a good idea to have those new partitions in a size which is sufficient to house the original XPs image. It's size depends on the used space. Choosing a partition-size equal to the original one is a safe choice. The rest of the drive can/must be used for logical partitions of which one is used for the Debian-installation right now.
For now just follow the Debian-installers instruction.
When asked to choose additional packages: Don't. There's no need for a GUI or WEB-server, now.

5 ntfsclone

Back to contents

Once the installation is complete login into the console and apt-get the ntfsprogs-package and an additional hex-editor. As root type apt-get install ntfsprogs hexedit Next we start the actual cloning. When calling ntfsclone it's important to keep the arguments in the right order. Unless one wants to overwrite ones XP-installation with an image of an empty partition. It's ntfsclone --overwrite /dev/dest /dev/source In our case ntfsclone --overwrite /dev/hda2 /dev/hda1 will start the cloning for hd2 and, a "little" bit later ntfsclone --overwrite /dev/hda3 /dev/hda1 does the same for hda3.

6 Modify NTFS-Bootsector

Back to contents

Now, the boot-sectors of the newly cloned XP-partition have to be modified. The partition(s) in front of the new ones have to be "skipped". This is done by inserting an offset into the partitions boot-sector. But first we've got to determine where they start. fdisk -ul /dev/hda shows:

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *          63    40965749    20482843+   7  HPFS/NTFS
/dev/hda2        40965750    81979694    20506972+   7  HPFS/NTFS
/dev/hda3        81979695   122993639    20506972+   7  HPFS/NTFS
/dev/hda4       122993640   181582694    29294527+   5  Extended
/dev/hda5       122993703   181582694    29294496   83  Linux
The interesting values are listed in the "Start"-column but have to be converted into hexadecimal and rearranged in order. printf "0x%llx\n" 40965750 printfs 40965750 in hexadecimal format 0x2711676
printf "%x" 40965750 would have done, too.
The hexadecimal value 2711676 has to be rearranged further. The digits have to skewed by pairs following this method: 0xABCDEFGH => GH EF CD AB
For 2711676 this results in 76167102
Since we've got 4 pairs to skew but only 7 digits available we simply add a leading 0. This is as neutral in the hexadecimal system as it is in the more familiar decimal system.
Now 76167102 has to be inserted into hda2s boot-sector. That's done with hexedit /dev/hda2
Move the cursor to position 0x1c and type in 76 16 71 02, then save&quit with <STRG>-X
Use the same procedure for hd3.

7 Bootmanager grub

Back to contents

In this scenario the first partitions XP should be allowed to "see" the newly cloned ones. We will, a little bit further on, used it to edit the cloned BOOT.INIs.
If we would boot up the new XPs now they would still see the other XPs, mingle drive-letters and end up "confused". So, when booting the new XPs for the first time, the other XPs have to be hidden. They may be exposed later.
Hiding is easily achieved by editing /boot/grub/menu.lst These are the relevant entries for booting into XP the first time.

title         Master-XP on hda1
unhide        (hd0,0)
unhide        (hd0,1)
unhide        (hd0,2)
root          (hd0,0) 
chainloader +1

title         Cloned XP on hda2
hide          (hd0,0)
unhide        (hd0,1)
hide          (hd0,2)
root          (hd0,1)
chainloader +1      
title         Cloned XP on hda3
hide          (hd0,0)
hide          (hd0,1)
unhide        (hd0,2)
root          (hd0,2)
chainloader +1


Back to contents

One last thing is to be done. The new XPs BOOT.INIs still point to the first partition. XP wouldn't accept that and stop booting giving an AUTOCHECK PROGRAMM NOT FOUND - SKIPPING AUTOCHECK-error. So the "Mother of XPs" has to be booted to edit the BOOT.INIs on the cloned partitions. The number of the partition to boot has to be adjusted. In case of hda2:

[boot loader]
[operating systems]
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="XP on hda2" /fastdetect /NoExecute=OptIn

9 Final steps

Back to contents

Finally the two clones may be booted too allow them to "rebuild" their registries. Now customising them to their special duties can begin.