0% found this document useful (0 votes)
52 views10 pages

Learning Linux Commands - How To Repair and Clone Disk With Ddrescue

This document provides instructions on how to use the ddrescue tool to repair and clone disks on Linux systems. It explains how to install ddrescue, use it to clone a disk or partition to an image file or other storage device, and optionally retry bad sectors to attempt data recovery.

Uploaded by

mancangkul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views10 pages

Learning Linux Commands - How To Repair and Clone Disk With Ddrescue

This document provides instructions on how to use the ddrescue tool to repair and clone disks on Linux systems. It explains how to install ddrescue, use it to clone a disk or partition to an image file or other storage device, and optionally retry bad sectors to attempt data recovery.

Uploaded by

mancangkul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Menu

How to repair and clone disk with ddrescue


21 July 2022 by Korbin Brown

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
How to repair and clone disk with ddrescue

Software Requirements and Linux Command Line Conventions

Category Requirements, Conventions or Software Version Used

System Any Linux distro

Software ddrescue

Privileged access to your Linux system as root or via the sudo


Other
command.

# – requires given linux commands to be executed with root privileges


either directly as a root user or by use of sudo command
Conventions
$ – 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.

To install ddrescue on Ubuntu, Debian, and Linux Mint:

$ sudo apt install gddrescue

To install ddrescue on Fedora, CentOS, AlmaLinux, and Red Hat:

$ sudo dnf install ddrescue

To install ddrescue on Arch Linux and Manjaro:

$ 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.

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 .

$ sudo ddrescue -d /dev/sdX backup.img backup.logfile


Note that the -d option will force ddrescue to ignore the kernel’s cache and instead
access the disk directly.

ddrescue process of cloning the partition to an image file

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.

$ sudo ddrescue -d -r3 /dev/sdX backup.img backup.logfile

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.

$ 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.

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 .

$ 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.

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.

Related Linux Tutorials:


How to recover partition table in Linux
How to partition a drive on Linux
An Introduction to Linux Automation, Tools and Techniques
How to format USB with exFAT on Linux
How to partition USB drive in Linux
How to manipulate gpt partition tables with gdisk and sgdisk…
How to manipulate partition tables with fdisk, cfdisk and…
Clone partition on Linux
Mastering Bash Script Loops
How to Burn ISO to DVD on Ubuntu 22.04 Desktop

System Administration
administration, backup, filesystem, storage
Desktop shortcuts creation in Linux
How to disable Plymouth on Linux

Comments and Discussions

Start Discussion 0 replies

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

18.04 administration apache applications backup bash beginner browser centos

centos8 commands database debian desktop development docker error fedora

filesystem firewall gaming gnome Hardware installation java kali multimedia


networking nvidia programming python raspberrypi redhat rhel8 scripting security
server ssh storage terminal ubuntu ubuntu 20.04 virtualization webapp webserver

ABOUT US

FEATURED TUTORIALS
VIM tutorial for beginners

How to install the NVIDIA drivers on Ubuntu 20.04 Focal Fossa Linux

Bash Scripting Tutorial for Beginners

How to check CentOS version


How to find my IP address on Ubuntu 20.04 Focal Fossa Linux

Ubuntu 20.04 Remote Desktop Access from Windows 10

Howto mount USB drive in Linux

How to install missing ifconfig command on Debian Linux

AMD Radeon Ubuntu 20.04 Driver Installation

Ubuntu Static IP configuration

How to use bash array in a shell script

Linux IP forwarding – How to Disable/Enable

How to install Tweak Tool on Ubuntu 20.04 LTS Focal Fossa Linux

How to enable/disable firewall on Ubuntu 18.04 Bionic Beaver Linux

Netplan static IP on Ubuntu configuration

How to change from default to alternative Python version on Debian Linux

Set Kali root password and enable root login

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

How to check NVIDIA driver version on your Linux system

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: Change timezone

Raspberry Pi Kali Linux headless setup

How to change username on Linux

Raspberry Pi as Minecraft Server

Setting Up GPT4All on Ubuntu/Debian Linux

Setting the Root Password on Ubuntu 24.04 Linux

Cloud Gaming with GeForce NOW on Ubuntu / Debian Linux

Setting the Hostname on Ubuntu 24.04


Setting a Static IP Address in Ubuntu 24.04 via the Command Line

Quick Guide to Enabling SSH on Ubuntu 24.04

Running Ubuntu 24.04 LTS on Docker

How to set battery charge thresholds on Linux

How to disable IPv6 on Linux

KDE Desktop installation on Ubuntu 24.04

Introduction to LVM thin provisioning

Ubuntu 24.04 LTS vs 22.04 LTS: A Comparison Guide and What’s New

Setting Up a LAMP Server on Ubuntu 24.04

How to create a backup with Proxmox backup client

Customizing and Utilizing History in the Shell

© 2024 TOSID Group Pty Ltd - LinuxConfig.org

You might also like