So I got some new systems for my parents. Needs to have Windows 7 on them, complete with a number of applications they use. Quite a lot of work to prepare one (I’m quite a bit of a windows noob), so didn’t want to do it twice.

Searched the internet for information and finally got some good tips from a friend up north.

To begin I made an image backup of the installed system. Unsure if my attempts to copy it to the second system would be successful, I wanted to make sure I had a backup. So in true Linux fashion I booted the system over the net using my PXEBoot with a UnionFS based NFS root and a kernel supporting all the hardware.

Now to make an image. The system has 3 partition, the first one seems to be VFAT and the other 2 NTFS. So to prepare I got some tools I needed on the NFS image:

apt-get install ntfsprogs openssh-client

I copied everything to my fileserver over ssh.

To make it a bit more reproducable, I made it into a (stupid) simple shellscript. First it backups the MBR and partition table. Then it just block level backups the first partition and uses ntfsclone to backup the second and third partitions.

#!/bin/bash BASEDIR=/var/backups

echo “Creating image with name $1” echo “Press enter to start” read line echo “Dumping MBR” dd if=/dev/sda bs=512 count=1 | ssh fileserver “cat - > $BASEDIR/$1.bootsect” echo “Dumping partition table” sfdisk -d /dev/sda | ssh fileserver “(cd $BASEDIR ; cat - > $1.parttable)” echo “Imaging partition 1” dd if=/dev/sda1 of=- bs=1024 | gzip -c | buffer -S 10240 | ssh fileserver “(cd $BASEDIR ; cat - > $1.sda1.gz)” echo “Imaging partition 2” time ntfsclone –save-image –output - /dev/sda2 | gzip -c | ssh fileserver “cat - > $BASEDIR/$1.sda2.gz” echo “Imaging partition 3” time ntfsclone –save-image –output - /dev/sda3 | gzip -c | ssh fileserver “cat - > $BASEDIR/$1.sda3.gz”

So using this shellscript I first backuped the system.

Then it was time to get Windows in such a state that it could be transferred to another system (exactly the same hardware BTW). I ended up using sysprep to do this. It seems this is the best way to start it. Start a cmd window and do:

cd c:windowsSystem32sysprep sysprep /oobe /generalize /shutdown

After waiting for a bit this failed. Fortunatly the command leaves behind a logfile in the directory:

Panther/setuperr.log

That gave me at least some clue. It turned out you have to stop the service:

WMPNetworkSvc

After stopping the service, the sysprep command ran without a problem.

Now I booted the system over the network again and made a new image with the same shellscript.

Then I hooked up the second system and booted that off the network. I made a new script to restore the image.

#!/bin/bash BASEDIR=/var/backups

echo “Restoring image: $1” echo “Press enter to continue” read line

scp fileserver:$BASEDIR/$1.bootsect /dev/null > /dev/null 2>&1 if test $? != 0 then echo “Error, no such image: $1” exit 1 fi echo “Restoring partition table” ssh fileserver “cat $BASEDIR/$1.parttable” | sfdisk -f /dev/sda echo “Restoring MBR” ssh fileserver “cat $BASEDIR/$1.bootsect” > /dev/sda echo “Restoring partition 1” ssh fileserver “cat $BASEDIR/$1.sda1.gz” | gzip -cd > /dev/sda1 echo “Restoring partition 2” ssh fileserver “cat $BASEDIR/$1.sda2.gz” | gunzip -c | ntfsclone –restore-image –overwrite /dev/sda2 - echo “Restoring partition 3” ssh fileserver “cat $BASEDIR/$1.sda3.gz” | gunzip -c | ntfsclone –restore-image –overwrite /dev/sda3 -

Using the script I restored the image.

And, surprise, surprise, the system actually booted Windows 7! Although the system behaves like a fresh install (you have to enter user settings, product code, accept license etc), everything is still there. So no reinstalling software etc.