avatar

Guide to Data Recovery with ddrescue

When disaster strikes and you’re faced with a failing hard drive or corrupted data, ddrescue can be your lifeline. Designed to rescue data from failing drives with a sophisticated multi-phase approach.

General rules:

What Makes ddrescue Special?

Unlike simple tools like dd, ddrescue is specifically designed for data recovery. It uses an algorithm that:

Basic Usage

The simplest way to start a recovery of a disk is:

ddrescue -d /dev/sda output.img output.mapfile

Always use a mapfile! It allows you to:

Example Scenarios

Scenario 1: Recovering a Specific Partition

If you only need to recover a specific partition rather than the entire drive:

ddrescue -d /dev/sda1 partition1.img partition1.mapfile

Scenario 2: Partial Recovery with Size Limits

When you want to recover a specific region of the drive:

# Start at 30GB into the drive
ddrescue -i30GiB /dev/sda output.img output.mapfile

# Recover only 10GB
ddrescue -s10GiB /dev/sda output.img output.mapfile

# Combine both: Start at 30GB and recover 10GB
ddrescue -i30GiB -s10GiB /dev/sda output.img output.mapfile

Scenario 3: Recovery with Multiple Passes

For troubled drives, you might want to use specific passes:

# Only use passes 1, 3, and 4
ddrescue --cpass=1,3-4 /dev/sda output.img output.mapfile

# Add retries for stubborn sectors
ddrescue -r3 --cpass=1,3-4 /dev/sda output.img output.mapfile

Try without -r during the first run, to not hammer the bad sectors, after a full read re-run with retries.

Scenario 4: Working with Unknown Drive Sizes

Sometimes you need to calculate sizes dynamically:

input_size=500123456789
start=199000000000
ddrescue -i$start -s$(($input_size - $start)) /dev/sda output.img output.mapfile

Advanced Recovery Strategy

My recommended approach for recovering data from a failing drive.

  1. First Pass - Quick Recovery

    ddrescue -n /dev/sda output.img output.mapfile
    

    The -n flag skips the scraping phase, quickly getting the easy-to-read sectors.

  2. Second Pass - Retry Bad Sectors

    ddrescue -r3 /dev/sda output.img output.mapfile
    

    Now we retry bad sectors up to 3 times.

  3. Third Pass - Direct Access

    ddrescue -d -r3 /dev/sda output.img output.mapfile
    

    Using direct disk access as a last resort.

Understanding the Recovery Phases

ddrescue operates in multiple phases:

1. Copying Phase (Up to 5 passes)

2. Trimming Phase

3. Scraping Phase

4. Retrying Phase

Working with the Recovered Image

After recovery, you can mount the image read-only:

mount -o ro,loop output.img /mnt/recovery

Tips

  1. Always start without retries

    ddrescue -n /dev/sda output.img output.mapfile
    

    This gets the easy data first before stressing the drive with retries.

  2. Use direct access (if the Linux blockdev layer is locking up)

    ddrescue -d /dev/sda output.img output.mapfile
    

    Direct access can be faster but might not work on all systems.

  3. Consider reverse direction

    ddrescue --reverse /dev/sda output.img output.mapfile
    

    Sometimes reading backwards can help with certain types of damage.

  4. Monitor progress

    ddrescue -v /dev/sda output.img output.mapfile
    

    The -v flag provides detailed progress information.

The tool’s sophisticated multi-phase approach and ability to resume interrupted operations make it invaluable for data recovery. Whether you’re dealing with a failing drive, a corrupted partition, or just need to make a perfect copy of a device, ddrescue should be in your toolkit.