How to Use ‘ddrescue’ to Recover Data from Failing Hard Drive

Data recovery from a failing hard disk can be a daunting task, but with the right tools, it becomes manageable. One such powerful tool in Linux is ddrescue, which is a data recovery tool created to copy data from one file or block device (like a hard disk) to another.

It efficiently handles read errors and tries to recover as much data as possible, making it ideal for failing hard disks.

In this article, I’ll guide you through the process of using ddrescue to recover data from a failing hard disk in simple, easy-to-follow steps.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.

Installing ddrescue in Linux

Before using ddrescue, you need to install it on your Linux system, the command is usually available in the default repositories of most Linux distributions and can be installed using the package manager of your distribution as shown.

sudo apt install gddrescue         [On Debian, Ubuntu and Mint]
sudo yum install ddrescue         [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
sudo emerge -a sys-apps/ddrescue  [On Gentoo Linux]
sudo apk add ddrescue             [On Alpine Linux]
sudo pacman -S ddrescue           [On Arch Linux]
sudo zypper install ddrescue      [On OpenSUSE]    
sudo pkg install ddrescue         [On FreeBSD]

The ddrescue command is used to copy data from one location to another. It is designed to handle disks that are failing or have already failed.

The basic syntax of the command is as follows:

ddrescue [options] input_file output_file

Using ddrescue to Recover Data in Linux

First, identify the device names for both the failing disk and the destination disk by using the following lsblk command, which will list all block devices.

lsblk

Look for the device names (e.g., /dev/sda, /dev/sdb). Let’s assume /dev/sda is the failing disk and /dev/sdb is the destination disk.

Next, create a backup of the failing disk to a separate disk or storage device, which will ensure that you have a copy of the data before attempting to recover it.

sudo ddrescue -n -v -b 4096 /dev/sda /media/backup/sda_backup mapfile

Here is the breakdown of the command:

  • -n tells ddrescue to run in non-interactive mode.
  • -v increases the verbosity of the output.
  • -b 4096 sets the block size to 4096 bytes.
  • /dev/sda is the device to be backed up.
  • /media/backup/sda_backup is the location where you want to store the backup.
  • mapfile is the log file that keeps track of the progress and any errors encountered during the backup process.

Finally, run the ddrescue command to start the recovery process, and monitor the log file to keep track of which parts of the disk have been successfully copied.

sudo ddrescue -f -n /dev/sda /dev/sdb /path/to/logfile.log

Here, the -f forces the overwriting of the output file and -n instructs ddrescue to skip the scraping phase (useful for the initial pass).

After the initial pass, you can perform additional passes to try to recover more data from the bad sectors.

sudo ddrescue -d -r3 /dev/sda /dev/sdb /path/to/logfile.log

Here, the -d enables direct disc access, which can be faster and -r3 retries reading bad sectors three more times.

Verify Recovered Data in Linux

Once ddrescue completes, you should verify the recovered data on the destination disk by mounting it and checking the files.

sudo mount /dev/sdb /mnt
ls /mnt

After verifying the data, unmount the disks safely.

sudo umount /dev/sda
sudo umount /dev/sdb
Conclusion

Using ddrescue to recover data from a failing hard disk in Linux is a powerful and efficient method. By following these steps, you can maximize the chances of recovering your valuable data.

Remember to always handle failing disks with care and consider creating regular backups to prevent data loss in the future.

If this article helped, with someone on your team.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
Ravi Saive
I'm Ravi Saive, an award-winning entrepreneur and founder of several successful 5-figure online businesses, including TecMint.com, GeeksMint.com, UbuntuMint.com, and the premium learning hub Pro.Tecmint.com.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

2 Comments

Leave a Reply
  1. Could you please advise how to use ddrescue on CentOS 7 with an argument that shows the estimated remaining time when disk cloning starts?

    Reply
    • @Bolanie,

      To use ddrescue on CentOS 7 and display the estimated remaining time during disk cloning, you can include the --verbose and --progress options.

      sudo ddrescue --verbose --progress /dev/sdX /dev/sdY logfile.log
      
      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Something went wrong. Please try again.
Check your email for a magic link to get started.