Saturday, April 9, 2011

Repairing Mac HFS+ Partition table

Had one of these recently, was a WDGreen power 1.5TB drive that had suffered some media damage (perhaps the issue with 8sec head parking might have attributed to it? I tried reading the SMART data but the load/unload cycles were masked).
Before I even began I used ddrescue to sector-sector clone the HDD to another drive. Ubuntu rescue remix is good for this. I won’t go into details on how to use ddrescue, that is covered elsewhere. You need to be careful about the commands you enter, copying the destination drive to the source can have dire results.
Once that’s sorted. Bootup MacOSX (I tried this in Vmware with the cloned drive as an attached physical drive on the virtual machine). Grab a copy of Testdis,, and plonk it on your machine. You might have to have Rosetta installed for this to work properly (You can find this on the MacOS install DVD).
Do a partition scan (MAC) on the HDD (/dev/rdisk*), you should eventually reach a screen similar to this.
Next we’ll use PDISK to initialise the partition table. Keep that window handy while you open up another terminal.
- ‘sudo pdisk /dev/rdisk*’(* = wadever was for your HDD). Issue command 'i'.
It’ll enquire about block sizes and total size of device. Just hit enter through (3 times).
Now we’re gonna need that partition info. Type the command ‘c’ and it’ll ask where your 1st partition starts, how long it will be and what name you want for it. You have to repeat this for as many partitions as you have found on Testdisk.
For my case it’d be
First block: 40
Length in blocks: 409600
Name of partition: EFI
‘c’ (again)
First block: 409640
Length in blocks: 2929605344
Name of partition: HFS
There might be error messages telling you about “Requested base and length not in existing free partition”. For the moment just ignore them.
Once you’re sure you have it right. Issue ‘w’ and then it’ll prompt you if you want the structure written. Once done, I like to use Testdisk again on the HDD to make sure I have it correctly set up. If it is, Finder should automatically try to mount the drive, if the damage wasn’t too bad.
In my case it wasn’t so easy though, even after I’ve got the partition structure right (I checked and rechecked), the bloody thing still wouldn’t mount. I believe the journal area was corrupted enough to not let it work (fsck didn’t do anything as well, it was so broken it didn’t do anything). A run through with Diskwarrior was done and that made the data visible again.

1 comment:

  1. Thanks for your blog! Saved me a life!
    Was able to restore after converting simple disk to dynamic from windows.