Backup external drive to image using pv

Intro

After building my new PC, I wanted to backup the old drive to an image. This way, if I needed any files, I could mount the image and retrieve anything I needed. I connected a USB backup drive to my laptop, pulled the drive out of the old PC, and connected the old drive to my laptop with this.

In this case, my laptop’s internal drive is /dev/sda, my backup drive is /dev/sdb, and my source drive (from the old PC) is /dev/sdc. Note, there are three partitions on /dev/sdc and I want to backup all of them.

Backup

I was planning on using dd, which does block-level copying. This means I can copy all the files on the drive, as well as the filesystem itself, to a single image file (similar to an ISO file for a DVD). The typical dd command looks something like below, using an input file (if) and output file (of).

The downside to dd or pv is that since they’re doing block-level operations, they aren’t aware of free space. The image you make will be exactly the size of the hard drive you’re backing up. To save space, you could use gzip to compress the image.

Restore

Mount and browse

If you don’t want to restore the image to a disk just to retrieve a file, you can mount the image on your machine and browse through the filesystem. Since we know our image has three partitions, we need to find out where the partitions begin and end. We can do that using parted.