Mirroring A Hard Drive with DD in Linux

I recently bought a new hard drive for my laptop. Well if you can consider 3 months ago recently. I had grand plans of installing Mac OS on the drive, and making a hackintosh of my laptop. Well I got lazy, so this brand new hard drive sat in a box, until of course this week. With an impending move to Germany, I got new motivation to install the drive, at the very least to increase my hard drive size.

One of my big issues with upgrading my hard drive was I wanted to retain all my files, and well pretty much wanted everything to work as it did before (I have multiple partitions, running primarily Ubuntu but also Windows). After a little searching, the best solution appeared to use the dd command.

The beauty of dd is it copies data at the block level, thus you can do exact mirror of drives. While this does take a little extra time it does make for a perfect copy of your current drive. dd is simple to run, but make sure you use the flags correctly. If you reverse the input and output file you can easily destroy your existing drive. Here is the basic command:

dd if=inputfile of=outputfile

Well that is simple enough. To do my hard drive upgrade I simply booted off an Ubuntu cd, opened a terminal, plugged in my new hard drive via a USB case, then ran dd. The process took around 5 hours. When it was done I swapped out my old hard drive for the new one and my system booted flawlessly.

After checking the system booted fine, I booted the Ubuntu cd one more time, then ran gparted and resized my old partitions to take advantage of the extra space of the new drive.

dd is a really simple way to mirror drives or partitions, whether for backing up or migrating to new drives. Just make sure you are absolutely sure about your input and output files to the command, because if you get the wrong, you will find yourself in tears trying to recover your data.

Leave a Reply

Your email address will not be published. Required fields are marked *