Recovering 600 GB From a Dying Drive That macOS Couldn't Open
How I recovered a friend's failing 1 TB external drive with ddrescue, a hand-built HFS+ reader and targeted carving, working beside an AI coding agent.
- Written by
- Naresh Kumar
- Published
- Reading time
- 16 min
- Topic
- Tech & AI
A friend handed me a 1 TB WD My Passport that her Mac would no longer open. It held more than a decade of photos and videos, and the Time Machine backups of a laptop that no longer boots. For some of those files, this drive was the only copy left.
She was extremely worried. These were the most precious photos she had, and there was no other copy anywhere: not on the laptop, not in the cloud. If the drive was gone, so were they, for good.
So before I touched it, I was honest with her. Recovering a failing drive is delicate work, and one wrong move can make things worse. I promised I would do everything I could, but I couldn’t promise it would work. A drive with physical damage can fail completely partway through a recovery, and some of that is simply beyond anyone’s control. No guarantees, just my best effort. It felt important to say that out loud before starting, not after.
I did the recovery over about a day and a half with Claude Code (Claude Opus 5.5) as a working partner. I handled the hardware, set the rules and made the calls. The agent wrote and ran the tools, explained what it found, and kept a log as it went. This post covers what went wrong with the drive, why the usual fixes would have made it worse, and how we got back about 330,000 files with only one photo damaged.
Names, file contents and anything else personal are left out. Everything below is about the drive, not the person.
The symptoms
The drive appeared in diskutil list but never mounted. A read-only mount failed, and a read-only verify (fsck_hfs -fn) stopped at once:
could not get volume block 2, err 5
Error 5 is an I/O error: the drive physically couldn’t read that sector. Block 2 is where an HFS+ volume keeps its volume header, the record that tells macOS where everything else is. Without it, the Mac sees a disk of unknown contents.
A diagnostic script read 64 MB samples at 20 points across the disk. Every sample read fine at 80–270 MB/s. The damage was concentrated at the start of the data partition, and each failed read took about a minute to time out.
The rules, before touching anything
A failing drive gets worse every time it’s read, and a repair tool writes. So before doing anything else I set four rules:
- Never write to the source drive. No Disk Utility First Aid, no Erase, no Initialize.
- Image it once, to a different drive, and do all the work on the image.
- Lock the master image (
chflags uchg), so no tool could change it by accident. - Recover first, name later. Losing file names was acceptable. Losing data wasn’t.
First Aid is the worst thing you can run on a drive like this. It reads the damaged areas over and over, and then it “repairs” the file system by writing new structures over whatever it couldn’t read.
Step 1: Image the drive with GNU ddrescue
I used GNU ddrescue 1.30 from Homebrew instead of dd or Disk Utility’s image feature. The reason is its map file. ddrescue records which areas it has read, which failed and which it skipped, so a run can be stopped and resumed, and later passes go back only to the gaps.
The first run got stuck on a cluster of bad sectors near the start, about a minute per bad block. So we stopped it and restarted with options that skip ahead after an error and get the healthy 99.9% of the disk first:
caffeinate -i ddrescue -n -b 512 -s 1000170586112 \
-K 16Mi,1Gi -e +150 -T 15m /dev/rdisk4 image.img image.map
| Option | Why |
|---|---|
-n |
Skip the slow scraping phase on the first pass |
-K 16Mi,1Gi |
After an error, jump ahead 16 MiB, growing to 1 GiB, instead of grinding on a bad patch |
-e +150 |
Stop if 150 new bad areas appear, a sign the drive is dying fast |
-T 15m |
Stop if nothing reads for 15 minutes |
caffeinate -i |
Keep the Mac awake for the whole run |
The pass ran at about 95 MB/s and finished in a few hours. 999.998 GB was rescued, and 2.17 MB in 25 small areas couldn’t be read.
I skipped the final “scraping” pass, which retries each unreadable sector. On a drive in this state it would have meant days of extra wear for at most a couple of megabytes. Then I ejected the original and unplugged it. Everything after this point read only the image.
Step 2: Why macOS still couldn’t open the image
Out of 1 TB, 2.17 MB sounds like nothing. Where those bytes were is what mattered. When we lined the bad areas up against the volume’s own layout, nearly all of them landed on file-system metadata:
HFS+ keeps its index of every file and folder in the catalog B-tree. The leaf nodes of that tree hold the records that say “this file is called X, it lives in folder Y, and its data is at blocks Z.” About 133 of those nodes were unreadable, including the tree’s header node.
We tried the textbook repair on a clone of the image, never the master:
- rebuild the primary volume header from the backup copy at the end of the partition;
- turn journaling off;
- rebuild the catalog’s header node;
- run
fsck_hfs -fy -rto rebuild the rest.
fsck_hfs crashed after 29 minutes. That was the point where we stopped trying to make macOS mount the volume and started reading it ourselves.
Step 3: Writing our own HFS+ reader
HFS+ is well documented in Apple’s Technical Note TN1150. The agent wrote a small set of read-only Python scripts against it:
| Script | Job |
|---|---|
catindex.py |
Scan every node of the catalog B-tree, skip the ones that don’t parse, and load each surviving record into SQLite |
attrindex.py |
Index the compression attributes from the attributes B-tree |
tmtree.py |
Rebuild the folder tree, including folders whose own record was lost |
decmpfs.py |
Decompress files that HFS+ stored compressed |
extract.py |
Copy each file’s data out of the image, set its original date, and flag any file touching a bad area |
Scanning the B-tree node by node, instead of walking it from the root, was the key choice. A walk from the root dies at the first broken node. A scan picks up every leaf that survived, wherever it is. The index ended up with 4.19 million file records and 505,000 folder records.
SQLite was the index format because it let us ask questions with ordinary queries: “what was in this folder?”, “which files touch a bad area?”, “which records point to a folder we don’t have?” It was also fast enough on a laptop with no setup.
Rebuilding folders from thread records
Losing catalog nodes means losing some folder records, and with them the folder’s name. HFS+ has a useful redundancy here. Every file and folder also has a thread record, stored by its own ID in a different part of the tree, holding its name and its parent’s ID. When a folder’s main record is gone, its thread record usually isn’t:
This brought back the top-level photo archive itself, whose folder record was among the casualties. That one folder held 46,736 files (304 GB), all with their original names and folders.
Step 4: The Time Machine maze
Most of the drive was Time Machine backups: 15 complete snapshots from 2018 to 2023 and one unfinished one from 2025. Time Machine on HFS+ makes every snapshot look like a full copy of the Mac by using hard links. Two kinds needed decoding:
- File hard links. A file in a snapshot is a small stub (type
hlnk) pointing to aniNode<N>file in a hidden private folder, where the data actually lives. - Directory hard links. An unchanged folder is a stub (type
fdrp) pointing to a shareddir_<N>folder, so a backup with nothing changed costs almost nothing.
We extracted the newest complete backup in full. Then, going back in time, each older backup contributed only the files that weren’t in a newer one. The result is one readable copy of every version that mattered, not 16 copies of the same laptop. That run skipped 945,320 repeat entries.
Two more HFS+ details came up here:
- Transparent compression. 69,427 files were stored compressed (
decmpfs), with the data hidden in an extended attribute or the resource fork.decmpfs.pyhandles zlib (types 3 and 4) with Python’szlib, and LZVN (types 7 and 8) by calling Apple’s ownlibcompressionthroughctypes. Using the system decoder meant no third-party LZVN code to trust. - Fragmented files. A file split into more than eight pieces keeps the rest of its block list in a separate extents overflow B-tree. Large videos in particular would have come out truncated without it.
The Time Machine pass mattered more than I expected. The Photos libraries inside the backups held 14,611 originals (116 GB) that weren’t in the main photo archive at all. A last script copied every Photos-library original into one plain Year/Month folder. It used APFS clones (cp -c), so 126 GB of photos took almost no extra disk space on the working drive.
Step 5: Orphans, then carving what the index forgot
Two kinds of files still weren’t reachable.
Orphans are files whose records survived but whose chain of parent folders breaks before the top of the drive. A reachability pass found about 2,800 of them, including a camera’s SD-card dump and part of an old backup. They went into a Lost and found folder named by folder ID.
Files with no record at all are the hard case. Their record sat on a lost catalog node, so the index doesn’t know they exist. File carving finds files by their content signatures, but carving a whole terabyte would have produced hundreds of thousands of duplicates of files we already had.
So we carved only the blocks nobody claimed:
The steps:
- Read the allocation bitmap, the map of which blocks are in use. Parts of it were on bad sectors, so those bytes were treated as “all in use” to stay on the safe side.
- Subtract every block owned by an indexed file (including overflow extents), plus the B-trees and the journal.
- Concatenate the 806 leftover runs into one 7.9 GB file, with an index mapping each offset back to its position on the drive.
- Carve that file with PhotoRec 7.2, limited to photo, video and document types.
- De-duplicate every carved file against everything already recovered by hashing its first 64 KB. Hashing whole files was too slow for 160,000 media files on a spinning disk. The first 64 KB of a photo or video, with its headers and start of image data, was distinctive enough to match.
- Sort the new photos into folders by the date in their EXIF data.
Those files lost their names for good, so they’re called things like f12345678.jpg. But 402 photos and 89 videos came back that no other step would have found.
Step 6: Verification
Copying bytes isn’t the same as recovering files, so we checked the results in layers:
- Damage map. The extractor compared every file’s blocks with the ddrescue map. Exactly two files touched an unreadable area: one photo, which lost its last 21 KB, and an app cache file.
- Structure check on all 166,031 photos and videos: does each start with the right signature and end with the right end marker? 78 were flagged.
- Triage of the 78. 52 were complete JPEGs followed by zero padding, and 15 were thumbnails or app data. Most of the rest turned out to be broken before the drive failed: truncated exports, a 12-byte stub, blank files from an old SD card. Telling “the drive did this” apart from “it was already like that” mattered for an honest result.
- Decode tests on a random sample: 300 of 300 photos decoded with
sips, and 30 of 30 videos withffprobe. This catches damage inside a file that a header-and-footer check misses. - Databases. The Photos library database and the Messages database passed SQLite’s
PRAGMA integrity_check. - Documents. In a random sample of 200, all 176 real documents opened. The rest were Word lock files and one PDF that was already empty.
None of the checks needed anyone to look at what the photos showed. Signatures, decoders and integrity checks answered “is this file whole?” without opening anyone’s memories.
The result
| Files recovered | About 330,000 (about 600 GB) |
| Photos and videos | More than 60,000, not counting thumbnails and caches |
| Recovered in their original folders | All but about 3,700, which are in Lost and found |
| Damaged by the drive failure | 1 photo (last 21 KB), 1 app cache file |
| Not recoverable | 31 old document versions in a compression format we didn’t decode, and some Time Machine links to thumbnails and caches whose data was lost |
The deliverable is a plain folder tree with a short Read Me explaining each folder: the main archive, every Photos-library original by year and month, the deduplicated backups, and Lost and found. It goes onto a new drive, copied and checked file by file.
What I’d tell anyone with a failing drive
1. Stop, and don’t “fix” it. The first instinct is First Aid, and it’s the most dangerous one. Every read wears a failing drive, and every repair writes over the evidence. Image first, then experiment on copies.
2. A few megabytes in the wrong place can hide everything. 99.9998% of this drive was readable, and the Mac still showed nothing. Metadata is small, critical and often stored in one place. That’s why the structure of the file system matters as much as the data.
3. Work at the right layer. When the file system couldn’t be repaired, reading its records directly got back names and folders. Carving got back what the records had lost. Doing them in that order meant carving only 0.8% of the drive.
4. Verify, and be honest about what verification shows. “Recovered” should mean “decodes”, not “copied”. It also means saying what was broken before the failure, instead of blaming everything on the drive or claiming everything came back.
5. Keep two copies. The drive was the backup, and the laptop it backed up had died. One more drive, or a cloud copy, would have made all of this unnecessary.
Working with an AI agent on it
The agent did the work that would have taken me weeks alone: reading TN1150, writing B-tree parsers, decoding LZVN through libcompression, and keeping long jobs running and logged overnight. It also kept a handoff document current, so I could pick the job up after sleeping without reconstructing anything from memory.
It proposed most of the technical approaches. The decisions stayed mine:
- the no-writes rule;
- when to stop a ddrescue run;
- skipping the scraping pass;
- abandoning the
fsckroute; - spending a night on the Time Machine extraction;
- approving the carving of the unowned blocks.
So did the hands-on parts: plugging and unplugging drives, deciding when the original could go back in its box, and talking to my friend. Privacy was a rule too. Every check was structural, so nothing in the process needed anyone to look through her photos.
For a job where one wrong command can destroy the only copy of someone’s photos, that split worked well. The AI moved fast on the technical work; I owned every step that couldn’t be undone.