← Blog

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:

  1. Never write to the source drive. No Disk Utility First Aid, no Erase, no Initialize.
  2. Image it once, to a different drive, and do all the work on the image.
  3. Lock the master image (chflags uchg), so no tool could change it by accident.
  4. Recover first, name later. Losing file names was acceptable. Losing data wasn’t.
Read the failing drive once, then work only on copies The failing drive is read once, read-only, and then unplugged. Repair tools like First Aid, fsck and Erase are never run on it. The one read produces a master image, locked so nothing can change it. Repair experiments run on a clone of the image, and read-only tools index, extract and carve from it. Everything they produce goes into a separate folder of recovered files, and from there onto a new drive. Failing drive Read once, then unplugged ✕ First Aid, fsck, Erase Never run on it one read-only pass Master image, 1 TB Locked with chflags uchg, so no tool can change it Clone for experiments Repair attempts happen here, never on the master Read-only tools Index, extract, carve and verify Recovered files A separate folder, then copied to a new drive
The one rule that matters most: read the failing drive once, then never touch it again.

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
A plain copy versus ddrescue's first pass A plain copy reads from the start and gets stuck on the first cluster of bad sectors, retrying each one for about a minute, with most of the disk still unread. ddrescue's first pass skips ahead after each error, reads nearly all of the healthy disk, and leaves the bad areas and the skipped patches around them for a later pass. A plain copy Stuck on the first bad cluster, about a minute per sector, with almost the whole disk still unread ddrescue, first pass Read Unreadable Skipped, for a later pass
Illustrative, not to scale. The point of the first pass is to get the healthy data off while the drive still works.

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:

Where the unreadable areas were A bar for the whole 1 TB drive shows unreadable areas clustered in the first few gigabytes, plus a few scattered later. Zoomed into the first 6 GB: three unreadable areas sit on the volume header, allocation bitmap and journal info block, none on the attributes B-tree, and seven inside the catalog B-tree, the file system's index of every file and folder. The whole 1 TB drive 0 1 TB Zoomed in: the first 6 GB Attributes B-tree Catalog B-tree 0 3 GB 6 GB Volume header, allocation bitmap, journal info block 7 bad areas inside the index of every file Unreadable area File-system metadata
Unreadable areas plotted from snapshots of the ddrescue map file. Positions are approximate, and widths are exaggerated so they show.

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 -r to 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.

Walking the tree versus scanning every node Two copies of the same small B-tree, with one broken index node. Walking down from the root stops at the broken node, so the three healthy leaves under it are never reached. Scanning every node in the file finds all six healthy leaves, because each leaf node can be recognized and read on its own. Walk from the root ✕ 3 healthy leaves never reached Scan every node ✕ Every readable leaf is indexed
Simplified. Leaf nodes carry a type marker in their header, so each one can be found and read without the nodes above it.

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:

Rebuilding a folder from its thread record The folder record for ID 5120 was on an unreadable catalog node and is gone. Its thread record survives elsewhere, giving its name, Pictures, and its parent, 412. The file records that name 5120 as their parent also survive. Together they rebuild the path with the original names, folders and dates. Folder record for ID 5120 On an unreadable catalog node: gone Thread record key: 5120 name: "Pictures" parent: 412 File records parent 5120: IMG_0001.jpg IMG_0002.jpg … …/Pictures/IMG_0001.jpg Original names, folders and dates
Simplified, with made-up IDs. A file's record is keyed by its parent folder's ID, so it survives even when the parent's own record doesn'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 an iNode<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 shared dir_<N> folder, so a backup with nothing changed costs almost nothing.
Time Machine hard links, and extracting each file once Three backups from different years each contain the same photo as a hard-link stub pointing to a single iNode, which holds the data. The extractor follows the link, copies the data once, and skips every later stub for the same iNode. Across all backups it skipped 945,320 repeats. Backup, 2018 photo.jpg → iNode7731 Backup, 2020 photo.jpg → iNode7731 Backup, 2023 photo.jpg → iNode7731 …and 13 more snapshots iNode7731 The data, stored once Copied once, newest backup first 945,320 repeat entries skipped
Simplified. The extractor tracks every iNode it has copied, so each file comes out once no matter how many snapshots link to it.

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.py handles zlib (types 3 and 4) with Python’s zlib, and LZVN (types 7 and 8) by calling Apple’s own libcompression through ctypes. 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:

Finding blocks with no known owner Start with the 615 GB of blocks the allocation bitmap marks as in use. Subtract the blocks of every file in the index, plus the B-trees and the journal. What's left is 7.9 GB in 806 runs: in use, but owned by no known file. PhotoRec carved only those runs. After removing duplicates, it found 402 new photos and 89 new videos. Blocks marked in use Allocation bitmap: 615 GB − Blocks owned by something we know Every indexed file, the B-trees, the journal = In use, no known owner 7.9 GB in 806 runs → PhotoRec New after de-duplication 402 photos and 89 videos
Carving 0.8% of the drive instead of all of it.

The steps:

  1. 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.
  2. Subtract every block owned by an indexed file (including overflow extents), plus the B-trees and the journal.
  3. Concatenate the 806 leftover runs into one 7.9 GB file, with an index mapping each offset back to its position on the drive.
  4. Carve that file with PhotoRec 7.2, limited to photo, video and document types.
  5. 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.
  6. 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 with ffprobe. 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.
What the 78 flagged files turned out to be Out of 166,031 photos and videos checked, 78 were flagged. Of those, 52 were complete JPEGs followed by zero padding, 15 were thumbnails or app data, 10 were already broken before the drive failed, and 1 was damaged by the drive failure. 166,031 photos and videos checked 78 flagged by the structure check. On a closer look: Complete, plus zero padding 52 Thumbnails or app data 15 Broken before the failure 10 Damaged by the drive 1
Of 166,031 photos and videos, one was damaged by the drive itself.

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

The whole recovery, start to finish Seven steps: the failing drive, read only; a ddrescue image of 1 TB with 2.17 MB unreadable; a SQLite index of every surviving catalog record; extraction with names, folders and Time Machine links; orphan files whose folder chain broke; carving of blocks with no known owner; and verification with decode tests and an integrity report. 1. Failing drive Read only, never written. Unplugged after imaging 2. ddrescue image 1 TB, 2.17 MB unreadable, locked 3. Catalog index Every surviving record → SQLite 4. Extraction Names, folders, dates, Time Machine links 5. Orphans Files whose folder chain broke 6. Carving Only the blocks with no known owner 7. Verification Decode tests and an integrity report
Each step reads the locked image or the previous step's output, and nothing writes back.
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.

The folders on the new drive The new drive holds a Read Me and five folders: the main archive with original names and folders, about 304 GB; every Photos-library original sorted by year and month, about 126 GB; the Time Machine backups with each file kept once, about 194 GB; Lost and found, including the files recovered without names, about 5 GB; and a few loose files from the top of the old drive. New drive about 630 GB READ ME.txt what each folder is Main archive original names · 304 GB All Photos, by year/month 126 GB Time Machine each file once · 194 GB Lost and found incl. unnamed files · 5 GB loose/ files from the top of the old drive
Generic folder names shown. Plain folders, so they open on any Mac without special software.

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 fsck route;
  • 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.