Recover Failing Drives with ddrescue on Linux

GNU ddrescue is a specialized, open-source data recovery tool designed to extract data from failing, damaged, or error-prone storage drives on the Linux operating system. This article explains the primary function of ddrescue, detailing how its multi-phase copying algorithm, non-destructive read strategy, and mapfile-tracking mechanism enable users to maximize the amount of recovered data while minimizing mechanical and physical stress on dying storage hardware.

Core Function and the Limitation of Standard Tools

Standard Linux cloning utilities like dd copy storage devices sequentially from beginning to end. When dd encounters a bad sector or I/O error on a failing hard drive or SSD, it typically aborts the operation, freezes, or fills the target image with corrupted zero-blocks while repeatedly stressing the damaged area.

GNU ddrescue solves this problem by decoupling the cloning process from the assumption that the drive is healthy. Its primary function is to copy data at the block level from one file or block device to another while gracefully isolating and working around read errors.

The Phased Recovery Algorithm

Rather than halting at the first sign of damage, ddrescue uses an intelligent, multi-phase algorithm to retrieve as much healthy data as possible before attempting to read problematic areas:

  1. Copying Phase: The tool rapidly reads large, healthy blocks of data across the drive. When it hits an error, it skips ahead rather than wasting time and wearing out the drive trying to re-read the damaged sector.
  2. Trimming Phase: Once the bulk of the undamaged data is secured, ddrescue returns to the edges of the skipped sections, narrowing down the exact boundaries of the bad sectors.
  3. Scraping Phase: In the final pass, ddrescue attempts to read the individual bad sectors byte-by-byte or sector-by-sector, retrieving any residual readable data that was skipped during the initial fast passes.

State Tracking via the Mapfile

A fundamental feature of ddrescue is its use of a mapfile (formerly referred to as a logfile). The mapfile records the status of every block on the source drive—marking blocks as non-tried, non-trimmed, non-scraped, bad, or finished.

This state tracking serves several critical functions:

Preservation of Fragile Hardware

Failing mechanical drives with damaged heads or degrading platters can experience catastrophic failure if subjected to continuous read attempts on bad sectors. By quickly capturing healthy sectors first and isolating bad blocks without repetitive head thrashing, ddrescue drastically lowers the chance of total drive death before critical files are retrieved.

The standard best practice when using ddrescue is to clone the damaged drive directly to an image file or a healthy secondary drive. All subsequent partition repairs, file system checks (fsck), or file carving operations are then performed on the cloned copy, leaving the original failing hardware untouched.