Wednesday, May 20, 2026

Linux - ddrescue

The following is a Linux Dictionary word of the day: ddrescue.

GNU ddrescue is a powerful Linux data‑recovery utility that copies data from one block device to another while intelligently handling read errors. Unlike the classic dd command, ddrescue:

  • Skips bad sectors automatically
  • Retries only the damaged areas
  • Uses a log file to track progress
  • Can resume recovery at any time

This makes it ideal for failing HDDs, SSDs, USB drives, SD cards, and corrupted partitions.

1. -d parameter

  • Direct disk access mode
  • Forces ddrescue to bypass the OS cache
  • Reads directly from the hardware

Useful for failing drives where caching may cause delays or hangs

Use when: recovering from physically damaged or unstable disks.

2. -f parameter

  • Force writing to a block device
  • Required when the output target is a raw device (e.g., /dev/sdb)
  • Prevents accidental overwrites by requiring explicit confirmation
  • Use when: cloning disk → disk.

3. -r[n] parameter

Retry bad sectors

  • -r tells ddrescue to retry failed reads
  • -r3 retries 3 times
  • -r0 means no retries
  • -r-1 means retry forever
  • Used when: you want to squeeze every last readable byte from a failing disk.

Here’s a clean, production‑ready ddrescue command:

ddrescue -d -f /dev/mdev /dev/mdev2 ddclone.log

Breakdown:

-d → direct disk access

-f → force writing to block device

/dev/mdev → source disk

/dev/mdev2 → destination disk

ddclone.log → log file tracking recovery progress

Why the log file matters

If the recovery is interrupted, you can resume instantly:

ddrescue -d -f /dev/mdev /dev/mdev2 ddclone.log

ddrescue reads the log and continues exactly where it left off.

Best Practices for Safe Data Recovery

  • Always clone first, never work on the failing disk directly
  • Use a separate physical disk as the destination
  • Keep the log file on a healthy drive
  • Avoid mounting the failing disk
  • Use -r3 or -r5 for moderate retries
  • For severely damaged drives, use -r-1 (infinite retries) cautiously

Compared to other tools, ddrescue stands out because it:

  • Automatically handles bad sectors
  • Optimizes read order for maximum recovery
  • Uses a persistent log file
  • Works on any block device
  • Is fast, reliable, and open‑source
  • For Linux admins, technicians, and digital forensics specialists, ddrescue is simply indispensable.

Key Takeaways

ddrescue is the safest and most efficient Linux tool for disk cloning and recovery

  • Use -d for direct disk access
  • Use -f when writing to block devices
  • Use -r[n] to retry bad sectors
  • Always create and preserve a log file