How to back up a hard disk on Linux

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 dd command.

Prerequsite: Unmount the Disk Partition

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.

Back up a Disk Partition with dd

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 /mnt/disk1.

Restored a Saved Disk Image

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

Back up and Restore a Local Hard Drive to and from a Remote Host

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 [email protected]_host.

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.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin (1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g).

Please note that this article is published by 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 as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean