Skip to content
Go back

ddrescue vs TestDisk vs PhotoRec

By SumGuy 14 min read
ddrescue vs TestDisk vs PhotoRec

Your drive is making a sound it shouldn’t. A click. A whirring pause. That click-click-click that means your 3 AM is about to get very interesting.

You have three tools in your Linux recovery arsenal: ddrescue, TestDisk, and PhotoRec. Each one solves a different part of the puzzle. They’re not rivals — they’re a workflow. And if you use them in the wrong order, you’ll spend the next week fishing individual JPEG fragments out of a directory named RECOVERED_FILES while your original data sits on a drive that’s getting worse by the minute.

Let’s talk triage.


The Golden Rule: Image First, Operate Never

Before we get into the tools, nail this down: you do not operate on the original drive. Ever. Not even once.

Here’s the physics: a failing drive is a bet against entropy. Every access (read, write, seek) accelerates the failure. ddrescue knows this. TestDisk does not care. PhotoRec will cheerfully spin up a drive that’s halfway dead. The moment your drive makes a noise, you have a window—hours, maybe days—before it’s unrecoverable. You do not waste that window running recovery tools on the drive itself.

The rule: image the drive first, then work from the image.

This is not optional. This is not “best practice.” This is “if you touch the original, you lose the data.”


ddrescue: Cloning a Dying Drive

ddrescue (GNU ddrescue, not the BSD dd rescue mode) is block-level imaging for damaged media. Its job: copy every sector from a failing drive to an image file (or a new drive), and document which sectors it couldn’t read.

When to use ddrescue

How to use ddrescue

First pass: identify bad sectors (no retry)
sudo ddrescue -n /dev/sdX /path/to/image.img /path/to/mapfile.log

This is the fast pass. ddrescue reads every sector sequentially without retrying. Bad sectors are logged to mapfile.log. This takes 10 minutes for a 1 TB drive on a healthy path, hours if the drive is clicking.

The -n flag skips the scraping phase—if a sector fails, move on immediately. You’re mapping the battlefield, not winning it yet.

Then comes the second pass:

Second pass: retry bad sectors aggressively
sudo ddrescue -d -r3 /dev/sdX /path/to/image.img /path/to/mapfile.log

Now ddrescue retries bad sectors up to 3 times (-r3), uses direct I/O (-d), and updates the mapfile. It reads from the position where the first pass left off. This is slow—a single bad sector can take 10 minutes if the drive is dying—but you’re maximizing recovery.

Some people run a third pass with higher retry counts:

Optional third pass: maximum retry (use carefully)
sudo ddrescue -r10 -d /dev/sdX /path/to/image.img /path/to/mapfile.log

Each pass consumes the drive’s lifespan. Use it only if the first two passes left significant unread blocks.

Reading the mapfile

The mapfile is your recovery report:

# GNU ddrescue mapfile, version 1.14
# ipos size status
0x00000000 0x0000D000 +
0x0000D000 0x00003000 ?
0x00010000 0x000F0000 +
0x00100000 0x00020000 -

If you see a sea of ? and -, the drive is toast. If you see small pockets of bad sectors mixed with +, you recovered most of the data. The image file itself will have zeroes in the unrecoverable sectors.

After the image: verify and mount

Once you have an image, work from the image, not the drive:

Mount the image as a loop device
sudo losetup -f /path/to/image.img
sudo mount /dev/loop0p1 /mnt/recovery

Or if the filesystem is partially corrupted and normal mounting fails, use fsck on the image first:

Check and repair the filesystem on the image
sudo fsck.ext4 -y /dev/loop0

The original drive goes in a box. You do not power it on again unless you’re escalating to a professional recovery service.


TestDisk: Partition Table Repair

TestDisk is the Swiss Army knife for partition tables and boot sectors. It doesn’t care about file contents—it reconstructs the data structures that tell your OS “this is where the filesystem starts.”

When to use TestDisk

How to use TestDisk

TestDisk is interactive, but here’s the workflow:

Launch TestDisk on the image (not the drive)
sudo testdisk /path/to/image.img

The menu will ask you:

  1. Select image type — Intel (MBR) or Mac (Apple Partition Map) or EFI (GPT)
  2. Analyze — TestDisk scans the image and tries to reconstruct partitions
  3. Review found partitions — it shows what it found
  4. Write — commit the reconstructed partition table

Here’s the thing: TestDisk finds partitions by scanning for filesystem signatures (ext4 superblocks, NTFS boot sectors, etc.). It’s not magic, but it’s surprisingly effective.

Key point: TestDisk works on the partition table itself, not the filesystem inside. If your partition table is intact but the filesystem is corrupted, TestDisk won’t help. That’s where fsck and PhotoRec come in.

When TestDisk saves the day


PhotoRec: Filesystem-Agnostic File Carving

PhotoRec is a sledgehammer. It doesn’t care about filesystems, partition tables, or metadata. It scans the raw image for file signatures (magic bytes) and carves out anything it finds.

When to use PhotoRec

How to use PhotoRec

Launch PhotoRec on the image
sudo photorec /path/to/image.img

PhotoRec is menu-driven. You choose:

  1. Partition — which part of the image to scan (or leave it to scan the whole thing)
  2. File system type — just for analysis (PhotoRec doesn’t care; it carves by signature)
  3. Output directory — where to dump recovered files

Then it runs. And runs. On a 1 TB image, expect 30 minutes to an hour.

The PhotoRec reality

PhotoRec will find most of your files. But here’s what you get:

RECOVERED_FILES/
f0000000.zip
f0000001.jpg
f0000002.pdf
f0000003.jpg ← probably a fragment of the same JPEG as f0000001
f0000004.jpg ← another fragment
f0000005.jpg ← possibly a full file, possibly another fragment
[... tens of thousands more ...]

You do not get filenames. You do not get directory structure. You get raw files and fragments, named by position on disk.

Some files are whole. Most are fragmented, especially if the drive was used for a while. A 10 MB video might be 40 fragments scattered across gigabytes of disk. PhotoRec will find them, but they’re not stitched back together.

The aftermath: You’ll spend the next week:

PhotoRec is recovery of last resort. It works, but the UX is “dig through a dumpster.”


Filesystem-Aware Alternatives

If your filesystem is ext4, ext3, or ext2, consider extundelete instead of PhotoRec. It understands the filesystem and can recover deleted files with their original names and structure:

Recover deleted files from an ext filesystem
sudo extundelete --restore-all /dev/loop0p1

Deleted files are restored to RECOVERED_FILES/ with their original names (if the inode still has them).

For more sophisticated recovery, the Sleuth Kit (fls and icat) can carve files by inode:

List deleted files in an ext filesystem
sudo fls -r /dev/loop0p1 | grep "^\*"

These tools require the filesystem to still be recognizable, but the payoff is much better than raw carving.


The Workflow: What Order?

Here’s the triage decision tree:

Step 1: Image the drive with ddrescue

Terminal window
sudo ddrescue -n /dev/sdX /path/to/image.img /path/to/mapfile.log
sudo ddrescue -d -r3 /dev/sdX /path/to/image.img /path/to/mapfile.log

Step 2: Try TestDisk

Step 3: Try filesystem repair

Terminal window
sudo fsck.ext4 -y /dev/loop0p1

If fsck recovers the filesystem, you’re done. If the filesystem is still corrupted, escalate to extundelete (for ext*) or move to carving.

Step 4: Last resort—PhotoRec If the filesystem is toast and TestDisk can’t recover the partition table, PhotoRec carves files by signature. Prepare for thousands of fragments.


HDD vs SSD: The Playbook Changes

Hard drives fail gradually. Clicks, read errors, bad sectors that get worse over time. You have a window—hours to days—to image them before they become unrecoverable. ddrescue shines here.

SSDs fail differently. A failed NAND cell can cause a sudden, total loss of a block. SSDs often fail catastrophically—one day they work, the next day they don’t mount at all. The window is shorter. ddrescue still works, but if the SSD is electronically dead, you’re looking at a professional recovery service (they’ll remove the NAND chips and read them directly).

For both: image first, operate never. But for SSDs, if it doesn’t power on or recognize, skip the Linux tools and escalate.


The Prevention Tier: What You Should’ve Done

This whole mess is preventable:

RAID 1 (mirror)

Two drives, always in sync
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1

If one drive fails, the other has your data. No recovery needed.

ZFS with redundancy

ZFS pool with parity
sudo zpool create -m /pool pool raidz /dev/sda /dev/sdb /dev/sdc

One drive fails? Replace it. ZFS rebuilds from parity.

Snapshots

Daily snapshots of important data
sudo zfs snapshot pool/data@$(date +%Y%m%d)

You lose a file? Restore from snapshot.

Offsite backup

rsync to a remote server
rsync -av /data/ backup@remote:/backups/mydata/

House burns down? You still have your data.

SMART monitoring

Check drive health regularly
sudo smartctl -a /dev/sda

Bad sectors? Predictive failure? You see it coming and replace the drive before it dies.

Any one of these beats all three recovery tools combined. The best data recovery is the kind where you never need it.


When to Give Up and Call a Pro

There are limits:

Professional recovery is expensive ($500–$3000), but if the data is irreplaceable, it’s worth it. The cut-off: if you’ve run ddrescue twice and PhotoRec is your only option, and the data is critical, escalate.


The Decision Flowchart

Drive is dying
[Image with ddrescue: -n pass, then -d -r3 pass]
Does the image mount normally?
├─ Yes → Done. You recovered everything.
└─ No → Does fdisk/parted show partitions?
├─ Yes → [Run fsck on the image]
│ └─ Does it mount now?
│ ├─ Yes → Done.
│ └─ No → [Try extundelete or PhotoRec]
└─ No → [Run TestDisk to rebuild partition table]
└─ Did TestDisk find partitions?
├─ Yes → [Try fsck]
└─ No → [PhotoRec is your last option]

The Bottom Line

They’re not rivals. They’re a chain:

  1. Image the drive (ddrescue)
  2. Repair the partition table (TestDisk)
  3. Repair the filesystem (fsck or extundelete)
  4. Carve by signature (PhotoRec) if step 3 fails

And before you ever need these tools, keep backups. Seriously. RAID, snapshots, offsite copies. The three tools above are tactical recovery. Backups are the strategic win that makes recovery unnecessary.

Your 2 AM self—the one standing next to a clicking drive at 3:47 AM—will thank you.


Full Example: Recovering from a Failing 2 TB Drive

Here’s what it looks like in practice:

Step 1: Image the drive
sudo ddrescue -n /dev/sdd /var/cache/ddrescue_image.img /var/cache/ddrescue.log
# Output: ... ipos: 2000 GB, non-trimmed: 0 B, bad-sector: 5 GB ...
# Check the mapfile
tail -20 /var/cache/ddrescue.log
# 0xFFFFFFF... 0x... ? (lots of untried sectors at the end)

Drive is still spinning. Run the second pass:

Step 2: Retry bad sectors
sudo ddrescue -d -r3 /dev/sdd /var/cache/ddrescue_image.img /var/cache/ddrescue.log
# Runs for 4 hours, reducing bad sectors to 200 MB...

Now you have an image with most of the data:

Step 3: Mount the image
sudo losetup -f /var/cache/ddrescue_image.img
sudo mount /dev/loop0p1 /mnt/recovery
# Mounts, but the filesystem is clearly corrupted. Files are unreadable.

TestDisk:

Step 4: Repair the filesystem
sudo fsck.ext4 -y /dev/loop0p1
# Recovers lost+found/ with many of your files intact.

Success. You recovered 85% of your data with the original filenames and structure. The rest is fragmentary and lost. But you have your home directory, your photos, your docs.

This is why backups matter. But when a backup is not available, this workflow is your best hope.

Keep ddrescue close. Hope you never need it.


Share this post on:

Send a Webmention

Written about this post on your own site? Send a webmention and it'll show up above once verified.


Next Post
Jellyseerr Tagging Workflows for Real Libraries

Discussion

Powered by Garrul . Sign in with GitHub or Google, or post anonymously.

Related Posts