How to backup a hard disk on Linux

If you would like to backup your hard disk, there is a simple way to do it by using "dd" command. The dd command utility is used to copy files or disk images from one location to another. Using dd, you can backup an unmounted disk as a (compressed) disk image which is then stored in a separate local or remote disk. Here is how to backup and restore a hard drive using dd command.

In order to use dd to backup a hard disk, you should unmount the disk first. A mounted hard disk may have various filesystem activities, and dd'ing such a live system may capture partial writes, which can lead to corrupted disk image. If the disk you want to backup corresponds to the root partition, you can boot from a Linux Live CD, and proceed to back up the root partition while it is not mounted. When a disk is unmounted, you can backup the disk as follows.

$ sudo dd if=/dev/sda | gzip -c > /mnt/disk1/sda.img.gz

The above command makes a clone of /dev/sda, gzips it, and stores the compressed image in /mnt/disk1. To restore the saved disk image, you can do the reverse:

$ gunzip -c /mnt/disk1/sda.img.gz | sudo dd of=/dev/sda

If you would like to backup a local hard drive on to a remote host, you can do the following.

$ sudo dd if=/dev/sda | gzip -c | ssh user@remote_host "cat > /mnt/disk1/sda.img.gz"

The above commands does disk cloning, compresses it, and then securely transfers the gzipped image to a remote host. To restore the disk image from the remote location, do the reverse as follows.

$ ssh user@remote_host "cat /mnt/disk1/sda.img.gz" | gunzip -c | sudo dd of=/dev/sda

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

Leave a comment

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