Learning Linux Commands - How To Repair and Clone Disk With Ddrescue
Learning Linux Commands - How To Repair and Clone Disk With Ddrescue
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.
Software ddrescue
You can use the appropriate command below to install ddrescue with your system’s
package manager.
Step 1 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
Here we find the device path /dev/sdb1 which is the partition we want to clone
Step 2 Next, we will use the following command syntax to copy the partition to an
image file. We are using /dev/sdX in 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 backup.img .
Step 3 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.
Step 4 Next, we will copy the new image file to a different disk or partition. We can
use an ordinary dd command for this.
The -f option indicates that we are sending our output to a block device rather than a
file.
Step 5 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 .
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.
Closing Thoughts
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.
System Administration
administration, backup, filesystem, storage
Desktop shortcuts creation in Linux
How to disable Plymouth on Linux
NEWSLETTER
Subscribe to Linux Career Newsletter to receive latest news, jobs, career advice and featured
configuration tutorials.
SUBSCRIBE
WRITE FOR US
LinuxConfig is looking for a technical writer(s) geared towards GNU/Linux and FLOSS
technologies. Your articles will feature various GNU/Linux configuration tutorials and FLOSS
technologies used in combination with GNU/Linux operating system.
When writing your articles you will be expected to be able to keep up with a technological
advancement regarding the above mentioned technical area of expertise. You will work
independently and be able to produce at minimum 2 technical articles a month.
APPLY NOW
TAGS
ABOUT US
FEATURED TUTORIALS
VIM tutorial for beginners
How to install the NVIDIA drivers on Ubuntu 20.04 Focal Fossa Linux
How to install Tweak Tool on Ubuntu 20.04 LTS Focal Fossa Linux
How to Install Adobe Acrobat Reader on Ubuntu 20.04 Focal Fossa Linux
How to install the NVIDIA drivers on Ubuntu 18.04 Bionic Beaver Linux
Nvidia RTX 3080 Ethereum Hashrate and Mining Overclock settings on HiveOS Linux
LATEST TUTORIALS
Setting Up Virtual Machines with QEMU, KVM, and Virt-Manager on Debian/Ubuntu
Ubuntu 24.04 LTS vs 22.04 LTS: A Comparison Guide and What’s New