Last updated on August 20, 2020 by Dan Nanni
If you would like to backup your hard disk, there is a simple way to do it by using
dd command. The
dd command-line utility is used to copy files or disk images from one location to another. Using
dd, you can back up 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
In order to use
dd to back up a disk partition, you should
unmount the disk partition first. A mounted hard disk may have various filesystem activities, and running
dd on such a live system may capture partial writes, which can lead to corrupted disk image. However, if the disk that you want to back up is the root partition, you can boot from a Linux Live CD, and then unmount the root partition.
Assuming that a disk partition (
/dev/sda) is unmounted, you can use the following command to back it up.
$ sudo dd if=/dev/sda | gzip -c > /mnt/disk1/sda.img.gz
The above command makes a clone of
/dev/sda, compress the cloned disk with
gzip, and stores the compressed image in
To restore the saved disk image, you can use the following command, which does the reverse of above backup:
$ gunzip -c /mnt/disk1/sda.img.gz | sudo dd of=/dev/sda
If you would like to back up a local hard drive and move it to a remote host directly, you can do the following.
$ sudo dd if=/dev/sda | gzip -c | ssh [email protected]_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 via SSH. For it to work, you need to enable password-less key authentication for
To restore the disk image from the remote location, do the reverse as follows.
$ ssh [email protected]_host "cat /mnt/disk1/sda.img.gz" | gunzip -c | sudo dd of=/dev/sda
For more advanced disk image backup/recovery options, check out Clonezilla.
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.