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.
In this tutorial you will learn:
- How to install ddrescue on all major Linux distros
- How to repair/clone disk or partition to image file
- How to repair/clone disk or partition to another storage device
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to install ddrescue on all major Linux distros
Before getting started, you will need to install ddrescue on your system. The tool is not usually installed by default, but can easily be downloaded and installed from your distro’s online software repositories.
You can use the appropriate command below to install ddrescue with your system’s package manager.
$ sudo apt install gddrescue
$ sudo dnf install ddrescue
$ sudo pacman -S ddrescue
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
- Next, we will use the following command syntax to copy the partition to an image file. We are using
/dev/sdXin the example below, but you would just need to substitute your own partition or device in place of it. The contents will be written to a file called
$ sudo ddrescue -d /dev/sdX backup.img backup.logfile
Note that the
-doption 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
-roption 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
ddcommand for this.
$ sudo dd if=backup.img of=/dev/sdX
ddrescuecommand can be used.
$ sudo ddrescue -f backup.img /dev/sdX clone.logfile
-foption 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
$ sudo ddrescue -d -f /dev/sdX1 /dev/sdX2 clone.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.
In this tutorial, we saw how to install the ddrescue tool on all major Linux distros. We then saw how to use ddrescue to clone a disk or partition to an image file or other device, while recovering as much data as possible in the process. ddrescue is a helpful tool to copy raw data from corrupted devices, as it handles errors intelligently in an attempt to rescue data.