Skip to content
TestDisk & PhotoRec

TestDisk & PhotoRec

Two tools in one formula: one puts the partition table back, the other ignores it entirely.

Homebrew formula

What it does

TestDisk finds partitions that are still on the disk but no longer in the partition table, and can write the table back — the fix for a volume that vanished after a bad diskutil command or a failed resize. It also repairs FAT and NTFS boot sectors and undeletes from several filesystems.

PhotoRec gives up on the filesystem and carves: it scans the device for known file signatures and writes out everything it recognises, hundreds of formats deep. Filenames and directories are gone — you get f0012345.jpg — but the contents come back.

sudo photorec /dev/rdisk4          # or point it at an image from ddrescue
sudo testdisk /dev/rdisk4

Notes

  • Both are terminal programs with a full-screen menu interface. Ugly, keyboard-driven, and the reference implementation the commercial tools are measured against.
  • Always work from an image if the disk is failing — see GNU ddrescue. Both tools accept an image file in place of a device.
  • Recovery onto the same disk you are recovering from overwrites the data you are trying to read. Write somewhere else.
On an Apple Silicon Mac the internal disk is encrypted by the Secure Enclave and trimmed aggressively. Carving deleted files off it generally does not work, and nothing else will do better — this is a case for having had a backup.

Alternative to

AlternativeTypeTrade-off
Disk DrillFreemiumPreviews what it found before you pay, and shows original filenames more often
Data RescueSubscriptionCommercial support and a cleaner report, on a subscription
RecuvaFreemiumThe usual Windows recommendation; no macOS build
foremostOpen sourceCarving only, scriptable, far fewer formats
R-StudioPaidDeeper RAID and network recovery, priced accordingly

Install

brew install testdisk

PhotoRec ships in the same formula.

Links

This post is licensed under CC BY 4.0 by the author.
Last updated on