Copying the contents of a hard disk drive and an opportunity to revisit Linux

My current 80GB HDD was running low on disk space and so it was time for an upgrade. My plan was to copy the data from the old HDD to a new 500GB one and extend the one and only system partition. A straightforward task.

Now, the PC in question has only one SATA port on the motherboard so that ruled out a straight disk-to-disk copy, complicating things slightly. I decided to copy the existing data to a Windows fileserver on my local network, install the new disk and copy it back. Using an external USB hard disk would’ve been a viable alternative.

I don’t know how to do a straight sector copy in Windows without resorting to third-party software or writing code, so I decided this would be a good opportunity to try a Linux-based “Live CD”. I chose Ubuntu simply because it was the first that came to mind and I knew it would have almost all the utilities that I needed right there on the CD.

First impressions… everything just works. Booting from the Ubuntu CD, after a minute or so I’m looking at the GNOME desktop. Wireless networking is working; video is working; impressive!

To mount the SMB share on my Win fileserver, I needed to grab smbfs …

sudo apt-get install smbfs

… and mount the share:

smbmount \\\\myserver\\myshare ./images –o user=myuser

I piped the existing HDD data through gzip to save on storage and network bandwidth:

sudo dd if=/dev/sda bs=512 | gzip > ./images/sda.img.gz

After a few hours of network copying, I swapped out the old HDD for the new and copied the data back:

gzip –c -d ./images/sda.img.gz | sudo dd of=/dev/sda bs=512

Note: I copied every sector including the MBR / partition table from the old to the new disk. This approach will only work if both disks have the same geometries.

dd responds to the USR1 signal by writing status to stderr, so I tracked progress (updating every 2 minutes) during long running dd operations using:

sudo watch –n 120 killall –s USR1 dd

I then used GParted to take care of resizing the NTFS partition to occupy the entire disk.

After a reboot into Win XP and one chkdsk later, I had more than 400GB free disk space.

Disclaimer: I don’t recommend you follow this approach unless you’ve backed up your data, are prepared for the possibility that things may turn bad and have a reasonable idea of what you’re doing.

Comments are closed.