ddrescue is a tool that can be used to repair and clone disks on a Linux system. This includes hard drives, partitions, DVD discs, flash drives, or really any storage device. It performs data recovery by copying data as blocks.
If ddrescue encounters errors from the data it’s trying to copy, it can discard them and keep only the good data. This makes it an ideal tool when trying to recover data from a corrupted disk. In this tutorial, you will learn how to install ddrescue and use it to clone a full disk or partition, and write that data to an empty storage space.
To install ddrescue on Ubuntu, Debian, and Linux Mint:
$ sudo apt install gddrescue
Clone a partition to image file or other disk
In the section, we will use ddrescue to clone a partition or full disk (the process is the same) to an image file. That file can that be written to another disk or partition afterwards. We will also show the process to clone a partition directly to another disk, bypassing the image file creation and instead creating a direct clone onto new hardware.
- First, open a command line terminal and identify the device path to the hard drive or partition that you would line to clone. For this, you can use a tool like
lsblk
,fdisk
, etc.$ lsblk
- Note that the
-d
option will force ddrescue to ignore the kernel’s cache and instead access the disk directly. - Note that if you are trying to recover data from a corrupted disk, you may want to append the
-r
option after the first try above. This will instruct ddrescue to retry bad sectors in an effort to recover as much data as possible. You can specify the number of retries after the option. In this example, we will use 3 retries.$ sudo ddrescue -d -r3 /dev/sdX backup.img backup.logfile
- Next, we will copy the new image file to a different disk or partition. We can use an ordinary
dd
command for this.$ sudo dd if=backup.img of=/dev/sdX
Alternatively, the
ddrescue
command can be used.$ sudo ddrescue -f backup.img /dev/sdX clone.logfile
The
-f
option indicates that we are sending our output to a block device rather than a file. - If you want to clone a disk or partition directly to another, thereby bypassing any image file, you can do so with the following syntax. In this example, we are cloning partition
/dev/sdX1
to/dev/sdX2
.$ sudo ddrescue -d -f /dev/sdX1 /dev/sdX2 clone.logfile
$ sudo ddrescue -d /dev/sdX backup.img backup.logfile
After completing the steps above, you can access the cloned storage and will hopefully see all of your files there, assuming that ddrescue was successful in recovering them.