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:
- 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.
- Trimming Phase: Once the bulk of the undamaged data
is secured,
ddrescuereturns to the edges of the skipped sections, narrowing down the exact boundaries of the bad sectors. - Scraping Phase: In the final pass,
ddrescueattempts 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:
- Interruption Safety: If the failing drive disconnects, overheats, or causes the system to crash, the recovery process can be resumed from the exact point it stopped without re-reading already-cloned data.
- Multiple Recovery Passes: Users can run fast initial passes without retries, cool the drive down, and run subsequent passes with multiple retry attempts targeted strictly at unreadable blocks.
- Reverse Direction Reads: If a drive consistently
fails when reading forward, the mapfile allows
ddrescueto attempt recovery in reverse mode to capture data situated on the other side of a physical defect.
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.