12 September 2008

Cloning a Windows system using ntfsclone over ssh

I recently found myself in a situation where I needed to set up four hardware-identical machines with the same Windows setup and software installed. So instead of taking a couple of days to setup up all of them one at a time I decided to install one machine the way I wanted it and then just duplicate the hard drive onto the others. I could have taken the hard drive out and placed it in the next machine, but I decided that it would be easier to just put them on a network together and use ssh to transfer the data. At first I was going to do it using dd but dd would transfer the entire 40GB partition over bit for bit. This is terribly inefficient considering I was only using about 10GB of that. Enter ntfsclone. This program can create an image of an NTFS partition as well as restore said image to another NTFS partition.

First I had to make sure that the second machine had an NTFS partition setup on it. You won't want to do this if the hard drive you are copying to isn't identical to the original. In that case you would want to use something like the Windows XP install cd to format the drive and create the partition for you. You also need to make sure that your MBR has been cleared.
Since in my situation it couldn't hurt to just copy the partition table from the first machine to the second, I did something like the following:

$ sfdisk -d /dev/sda | ssh root@hostname sfdisk /dev/sda

This was adapted from http://www.partimage.org/Partimage-manual_Backup-partition-table

Then I started the ntfsclone:

$ ntfsclone --save-image --output - /dev/sda1 | ssh root@hostname ntfsclone --restore-image --overwrite /dev/sda1 -

This was adapted from http://man.linux-ntfs.org/ntfsclone.8.html

No comments:

Post a Comment