Relocating Windows to a new Hard Drive

Moving NTFS filesystems to different (sometimes larger) hard drive can be a nightmare. I’ve had one such nightmare recently and I thought it’d be worthwhile to document it here for others having similar problems. The below points are based on my experiences with Windows XP, but most of it relates to Vista and 7 as well I think.

  1. Make sure Windows is happy with the filesystem. You can do this by running chkdsk /f for each drive. Tell it not to forcibly unmount (it probably wont work) and let it do it on reboot instead. Do not leave these checks outstanding otherwise the Linux NTFS utilities wont let you do anything.
  2. Use ntfsclone from a Linux Live CD (Ubuntu has it by default). It’s pretty good, and quicker than dd. You use it on a partition-basis, and it has a handy image file format for saving efficiently, or even streaming over the network. Here’s some example commands I was using:

    For sending to a listening netcat server (which would be doing something like nc -l 9000 > image.gz)

    ntfsclone -s - /dev/sda1 | gzip -c | nc server 9000

    For receiving from a listening netcat server (nc -l 9000 < image.gz)

    nc server 9000 | gunzip -c | ntfsclone -r - /dev/sda1
  3. You must restore an ntfsclone image onto a partition of the same size. Therefore backup the old drive’s partition information. The important thing is how many sectors a partition is. You can then use something like fdisk to create a new partition with exactly the same number of sectors. Don’t worry, you can make it bigger later.
  4. gparted, available on Ubuntu Live CDs, will automate the resizing of both partitions and NTFS file systems, so I recommend using that. Otherwise, you’ll need to use a combination of a partition manager and ntfsresize. Remember shrinking a partition is harder, the filesystem might be too fragmented.
  5. You can use ms-sys (this was removed from the Ubuntu repos for some reason, Google for a DEB if you need one), or lilo, or the Windows Recovery Console (the FIXMBR command) to put a standard MBR on your new drive. That might be enough to get Windows to boot, but if Windows has moved relative to it’s original position on the original drive, it wont, see below.
  6. If you’ve moved Windows around on the hard drive (e.g. before, you had a silly diagnostic partition that came with your laptop, and now you don’t) then you need to tell NTFS the drive has a new start sector. To do this, I found a piece of C code on the (currently unavailable) linux-ntfs website. I don’t know how permanent that link is, so I have a copy of it here too, just in case.
  7. Changing the hard drive does not force re-activation (at least, not on Windows XP), but remember if you move the hard drive to a new computer, it will.
This entry was posted in Blog, Noteworthy. Bookmark the permalink.