Linux Commands

Use dd to Clone a Disk

The dd command in Linux is a powerful utility used to copy and convert a file. As in Linux, everything is considered as a file; even your hard disk drives. Hence, dd can also be used for cloning disks and partitions. The dd utility comes installed in almost all Linux distributions.

The dd utility in Linux can be used to:

  • Clone a disk
  • Clone a partition
  • Backup and restore the entire hard disk or partition.
  • Erase hard drive content

This post will describe how to use dd to clone a disk in Linux OS. The procedure demonstrated here has been tested on Linux Mint 20. For other Linux distributions, the same procedure can be used for disk cloning.

Note: Before running the dd command to clone the disk to the destination, remember that all the data on the destination will be lost, and you will not be informed about that. Therefore, make sure you specify the correct destination so that you may not lose your valuable data.

dd command syntax

The basic syntax of the dd command is as follows:

$ sudo dd if=source-disk of=destination-disk [option]

Where

  • if: used for specifying an input file
  • source-disk: It is the source disk from where files will be cloned
  • of: used for specifying an output file
  • destination-disk: It is the destination disk where you want to place the copied files
  • option: Different options can be used with the dd command like for progress, speed of file transfer, the format of the file, etc.

Clone an entire disk

  1. First, execute the lsblk command to view all the available disks on your system.
$ lsblk

Or you can also use the following command for viewing the disks:

$ fdisk -l

We have three disks /dev/sda, /dev/sdb and /dev/sdc. The /dev/sdb has two partitions /dev/sdb1 and /dev/sdb2. We want to make the exact copy from /dev/sdb to /dev/sdc. Both disks /dev/sdb and /dev/sdc have the same size, 5GB. You can copy a smaller disk to a larger disk, but you cannot copy a larger disk to a smaller one.

  1. To clone an entire disk /dev/sdb to /dev/sdc, we will use the following command:
$ sudo dd if=/dev/sdb of=/dev/sdc status=progress

This command tells dd to copy the source disk /dev/sdb to the destination disk /dev/sdc and shows the progress of the cloning process.

Once the cloning process has been completed, you will see a similar output.

  1. Now, the cloning has been done. If you run the lsblk command again, you will see that the destination disk /dev/sdc has the same partitions as the source disk /dev/sdb.

Clone a partition from one disk to another

Using the same above described procedure, a partition can be cloned from one disk to another. However, instead of specifying the disk, you will need to specify the partition you want to clone.

For instance, to clone a partition /dev/sdb2 to /dev/sdc2, the command would be:

$ sudo dd if=/dev/sdb2 of=/dev/sdc2 status=progress

That is all there is to it! Using the simple procedure described above, you can easily clone a disk or partition in your Linux system.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.