Fixing a Seemingly Dead Drive… Thanks to TestDisk

Well, that was a fun afternoon (can you detect the sarcasm?)

Those who know me well will know that I do like myself a little hardware and software fun from time to time. Fun equates to getting some program or other working, learning some new snippet of computer hardware fu, or perhaps getting my (now ancient) Mac Pros happy and alive with the latest Mac OS X operating system ten years after they were made.

Yes. More dead drives. It's becoming a thing...
Yes. More dead drives. It’s becoming a thing…

I also happen to have three hackintoshes in the house. Two identical ones made for my kids (one in each room). Based on the GA-67N chipset from Gigabyte, they’ve done pretty well for the past five years, and it means that our kids have their own computers for homework etc. More importantly, it means they don’t have to use our ‘real’ macs. Which if you don’t mind me saying, aren’t the kind of thing I can afford giving to my kids to use willy-nilly.

My other hackintosh is my Hackintosh Pro, a beast of a machine with 12 GB of RAID 0 media storage, a 12GB RAID 5 array, a RAID 0 1TB boot disk, and lots more beefy bits to take me up to a total of 30 TB of connected storage, 32 GB of RAM and a stonking graphics card. And yes, I use that because it’s cheaper than having a real up-to-date Mac Pro…

I digress. And I should also apologize for what follows. It’s late at night, and I haven’t quite put my usual ‘splainin’ hat on. So you’ll need to be a nerd like me to follow.

TestDisk did the thing.
TestDisk did the thing.

This morning, we went bouldering over in Tigard. Bouldering, as I discovered, is like rock climbing but using smaller walls. We then came back home, my son went off to a birthday party, my daughter disappeared to her room, and while my wife browsed the Internet, I played on Assasin’s Creed. With my noise cancelling headphones on, I completely missed the bit where my daughter comes downstairs and tells my wife that her computer just isn’t booting.

While it begins to boot (and therefore the bootloader is fine) it spends the next hour stuck on the booting screen with the progress bar and the Apple Logo.

I find out after my son gets back, and the game is about to start. To keep everyone happy, I head upstairs to try and fix the problem.

Normally, you can boot into single user mode when a Mac isn’t behaving, and fix any disk errors with /sbin/fsck -fy. But today, the drive wasn’t having any of it. Aside from the repeated attempts to fix itself (which ultimately was what was causing that hang my daughter saw) we had B-catalog problems, drive problems, and node problems.

So I take the drive out of her machine and pop it in one of mine. The drive is recognized, but the computer says the drive isn’t initialized. Because I knew there was something still readable, I headed back upstairs with the drive and put it back in my daughter’s machine. This time, armed with a new USB boot drive with a fresh 10.10.x installer on it.

Nope. Wouldn’t boot. Tried Clover bootloader (her machine still uses the old-school pre-Clover method).

Nothing.

So, in desperation, I head back downstairs and realize that the drive wasn’t built with a GPT partition table as modern mac drives usually are. It’s based on an MBR partition table, and for some reason, my mac wasn’t reading the partition table. In fact, my mac couldn’t’ even see a partition table on the drive.

Seriously. TestDisk fixed it... at least to a point where I could use other programs on it.
Seriously. TestDisk fixed it… at least to a point where I could use other programs on it.

I wondered if the drive partition table was screwed up in some way, and decided to find out. But none of the standard mac utilities (including the excellent Diskwarrior) could see anything on the drive.

Behold TestDisk, a free, command line utility that I’ve used before to recover an accidentally partitioned disk. I happened to have a copy on my machine, so I pointed my terminal window at the directory it lives in, and ran sudo ./Testdisk selecting the disk I knew wasn’t showing up as having even a partition on it.

After selecting the right partition table (Intel/PC partition for the MBR I knew the disc had) the command-line program asked if it should analyse the current partition structure. I clicked “Quick Search” and voila! it found the missing HFS+ partitions.

Then it was a matter of following the program’s directions, replacing the broken partition table with the one recovered from the disc (presumably from a superblock or some other backup on the disc).

Once my mac actually saw the drive, it was happy. Woo. Happy.
Once my mac actually saw the drive, it was happy. Woo. Happy.

The program tells you to reboot, and after doing so, the drive pops up on my machine. A quick bit of DiskWarrior action (because it now mounts) and all seems well with the world again. Yes, there are a few files and folders which seem unwell (DiskWarrior made me aware of them) but I can at least now see and use the drive to back it up.

There is a small problem however: the drive doesn’t want to boot yet, because the thing has lost its blessing as a consequence of me fixing the partition table.  I can fix that however, and if I’m honest, that’s super-easy to do because I’m going to be backing this drive and data up (and then reinstalling the OS anyway)

Why so much fuss over a child’s computer? Well, My daughter has various games in progress on the machine that she’d like to continue to play. And while I do have a backup of the entire drive up on Amazon Cloud drive (thanks Arq backup) I wanted to see if I could fix the thing locally. For the most part, that’s what I’ve done.

Once I’ve backed up the drive, I’m going to run a deep disc scan over night and see if there are any bad blocks. I’m skeptical of this and think that perhaps it was a shutdown gone wrong. But best to be safe.

What caused the problem in the first place? That’s a tough one. I think it may have been a hurried shutdown, or perhaps just a corrupted drive over time. Our old house did suffer fairly frequent power cuts, to the seed may have been set there.

I’ll let you know more as I have it. But in the meantime, get a copy of TestDisk. It’s awesome. Today. It stopped tears before bedtime.

Featured image: By Gerhard GeWalt Walter, CC0.