Upgrading A Windows Machine To a Smaller SSD using dd.

There are so many articles on migrating to a large magnetic drive to a smaller ssd drive.  I’ve tried a number of tools in the past, and all have worked.  But recently I’ve tried using some old-school methods.  dd is a tool that has been around for ages, it lets you take an in file / stream, and write it to an out file / stream.  So, for example, lets say you have two identical hard disks, you want to copy everything from one to another, say the source drive is /dev/sda, and the destination is /dev/sdb,  you can just do “dd if=/dev/sda of=/dev/sdb”.  It is a pretty powerful, but basic tool.  so it won’t provide any indication it’s doing anything.  And, if you accidentally mix up the if and of parameters, you have just destroyed data :)

But! What if you can’t get both drives into the computer at the same time?  I have a laptop I wanted to upgrade from a 500gb hdd to a 120gb ssd.  But, I didn’t have what I needed to connect both drives at the same time, but, I have a linux server on our home network.  Shrinking a drive is easy now days.  You can boot up a linux live usb stick, and use ntfs re-size to shrink the partition so the data is all at the beginning of the disk.

I used dd and ssh together to pipe the output of dd to a file on the server.  i.e.  “dd if=/dev/sda bs=1048 count=(some large number) | ssh joey@fs1 dd of=/data_brick2/laptop.img”  that’s it.  That easy.  Then, I swapped out the drives (while the laptop was running, you can do that safely with sata) and ran “ssh joey@fs1 dd if=/data_brick2/laptop.img | dd of=/dev/sda”

I didn’t dump the whole 500gb to the server, rather, using the bs, and count parameters, you can control how much data dd dumps.  I knew I had about 100gb of data on the drive, and since Ir an ntsf resize, it was all at the beginning, so I set the bs (block size) to 10k or so (1024 * 10), and then set the count to 1024*1024*1024*105/(1024 * 10).  Then, I used iftop to monitor the network traffic between the server and my laptop and could tell when the job was done.

Once the data was on the new ssd drive, you have to use parted or fdisk to change the partition size to be legal.  See, ntfs resize doesn’t actually change the partition size, it just moves all the data for the file system to the beginning of the partition, and resizes the file-system.  So the boot record that dd copied over says the partition was 500gb in size.  But, now it’s on a 120gb ssd.  Parted has an easy to use resize command.  I did that, it resized the partition, but it didn’t resize the file system…

So, the next step is to boot back into windows, run the disk partition tool, and you should be able to expand the partition by a few mb…  When you do this, Windows also resizes the file system at the same time, and Viola!  Now you have access to all the space on the SSD, everything is good, and you didn’t have to download or install anything.

If you’ve never used dd before, give it a try next time.  Just be 100% absolutely sure that you have if and of correct, and you know which drive is where so that you don’t loose any data.