Skip to main content
20 of 32
added 5 characters in body
klanomath
  • 67k
  • 10
  • 135
  • 204

The method to repair your disk and recover the GUID partition table is related to my answers to similar questions: HFS+ invalid number of allocation blocks and Hard drive no longer accessible.

Basically you have to find characteristic strings of JHFS+ volumes, use some simple math and common sense and have some luck to fix the GUID. And don't loose sight of your objectives when faced with this wall of an answer.

Additionally there are some fixed sizes and rules that help you to determine some of the sizes as well as some of the starting and the ending blocks of your "deleted" partitions.

 1. 1st block (block 0)                             = PMBR
 2. 2nd block (block 1)                             = Pri GPT header
 3. 3rd - 34th block (block 2 - block 33)           = Pri GPT table
 4. 41st - 409640th block (block 40 - block 409639) = EFI (aligned)
 5. 409641st - ??? block (block 409640 - block ???) = partition 1 (aligned)
 6. empty space 262144 blocks (aligned)
 7. ??? - ??? block (block ??? - block ???)         = partition 2 (aligned)
 8. empty space 262144 blocks (aligned)
 9. 7 empty blocks to keep alignment
10. the last 33 blocks except the very last one     = Sec GPT table
11. last block                                      = Sec GPT header
12. alignment rule: the start block and the sizes of all partitions (EFI, partition 1 & 2) and the major empty spaces are dividable by 8

Finally a gpt command should result in something similar like this output:

root# gpt -r -vv show /dev/disk1
gpt show: /dev/disk0: mediasize=3000592498688; sectorsize=512; blocks=5860532224
gpt show: /dev/disk0: PMBR at sector 0
gpt show: /dev/disk0: Pri GPT at sector 1
gpt show: /dev/disk0: Sec GPT at sector 5860532223
       start        size  index  contents
           0           1         PMBR
           1           1         Pri GPT header
           2          32         Pri GPT table
          34           6         
          40      409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
      409640  2930844728      2  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
  2931254368      262144         
  2931516512  2928753528      3  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
  5860270040      262151         
  5860532191          32         Sec GPT table
  5860532223           1         Sec GPT header

Hint: Since I can't create a disk of the same size as yours in Parallel Desktop some sizes are different than your original sizes

Preparation:

Backup your Mac and then detach all external drives except the one you want to recover.
Download and install wxHexEditor. Enable the root user and log-in as root.

Hint: While working with wxHexEditor don't use copy and paste. Enter everything manually! You might accidentally write directly to your disk.

Terminology

Block: Sector (in wxHexEditor)
Offset: The number of the Byte relative to the beginning of the device/volume starting with "Byte 0". E.g Block(512) 0 contains Byte 0 - Byte 511.

Determine your partitions` boundaries:

Open the Calculator. Open wxHexEditor. Check that you work in read-only mode ("Options" -> "File mode" -> "Read only"). In the menubar go to "Devices" -> "Open disk device" -> choose the appropriate diskNumber. Probably it's disk1. The disk should have one partition (disk1s1). Please try to arrange the wxHexEditor window like in the examples below with straight red lines.

Then hit the "Go to offset"-button (marked with the green circle) and enter 409640 exactly like in the picture below. Sometimes you have do that twice to jump to the correct sector. Re-check the correct sector by entering the offset (marked red) in the Calculator and divide it through 512.

enter image description here

If you see a similar picture you already found the beginning of your first partition (note the string HFSJ in block 409642!).

Now jump to the midst of your disk: Hit the "Go to offset"-button and enter block number (total blocks of your disk/2) ~ 2930266108.
This works if you've previously partitioned your disk with Disk Utility by simply choosing 2 partitions in the drop down menu. If you've adjusted the slider between the two partitions afterwards e.g. enlarged partition1 you have to jump to slightly bigger offset.

Now hit the "Find"-button (marked with the green circle) and enter HFSJ like in the picture below and hit find. This may take a while.

enter image description here

If the search was successful you've found the beginning of the second partition. Make a note of the block offset (=BlockOffset2). In my example the offset is 1500936455168. If you scroll to lower offset numbers the disk should be filled with 0s.

Since you have found the start sectors of both volumes and the rest usually is determined by the rules 1-12 mentioned earlier you may now fix the GUID table. Quit wxHexEditor. If you are asked to save changes don't save them!.


Now you have to do some math:

The first HFSJ string usually is found in the 3rd block of a JHFS+ volume.

So the first JHFS+ volume starts at block 409640 (also rule 5). The second JHFS+ volume starts at StartBlockOfVolume2 = BlockOffset2/512 - 2. In my example that's 1500936455168/512 -2 = 2931516514 -2 = 2931516512.

With the start block of volume 2 and the fixed empty space of rule 6 you may determine the end block of volume 1:

First block of volume 2 - 262144 (rule 6) - 1 = EndBlockOfVolume1.

In my example that's 2931516512 - 262144 - 1 = 2931254367

SizeOfVolume1 = EndBlockOfVolume1 - start block volume 1 (rule 5) + 1

In my example that's 2931254367 - 409640 + 1 = 2930844728

The only thing you need missing is the size of volume 2:

With the rules 8-11 from above you may now determine the last block of volume 2.

Total size of disk in blocks - 1 (rule 11) - 32 (rule 10) -7 (rule 9) - 262144 (rule 8) - 1 = LastBlockOfVolume2

SizeOfVolume2 = LastBlockOfVolume2 - StartBlockOfVolume2 +1


Rebuild a proper GPT:

Here I assume the identifier of your external disk is disk1. First you have to unmount your external disk in Terminal:

diskutil umountDisk disk1

Remove the current fdisk mbr with gpt:

gpt create -f /dev/disk1

First rebuild the EFI entry with:

gpt add -b 40 -i 1 -s 409600 -t C12A7328-F81F-11D2-BA4B-00A0C93EC93B disk1

Then add the first JHFS+ partition entry:

gpt add -b 409640 -i 2 -s SizeOfVolume1 -t 48465300-0000-11AA-AA11-00306543ECAC disk1

Then enter:

diskutil umountDisk disk1

and add the second JHFS+ partition entry:

gpt add -b StartBlockOfVolume2 -i 3 -s SizeOfVolume2 -t 48465300-0000-11AA-AA11-00306543ECAC disk1

Then again enter:

diskutil umountDisk disk1

Enter exit and quit Terminal.

Open Disk Utility and verify the disk and the two volumes for errors, but don't repair them. If no errors are found mount the volumes.


Work In Progress - Don't proceed until this notification has been removed

Addendum: 4k device in a 4k enclosure

If you happen to have an Advanced Format hard drive which has a 4096 bytes (4K) sector size in a 4k only enclosure (a hard drive enclosure with a controller not properly reporting a logical block size of 512 bytes for the AF HDD) some modifications have to be made to the above solution:

To jump to a given sector you have to divide the above data through eight.

Examples:

  • Instead of jumping to block(512) 409640 to find the assumed start sector of volume 1, jump to block(4096) 51205.

  • To find the middle of your HDD jump to total blocks(512) of your disk/16 instead of total blocks(512) of your disk/2

The math part stays the same. Changes may easily be adopted by introducing a factor 8 in the Rebuild a proper GPT part.


I hope this recovers your missing volumes.

If you run into problems (e.g you can't find the proper starting sector of your second volume), the verification throws a lot of errors, have doubts or questions immediately stop and contact me with a comment @klanomath!

klanomath
  • 67k
  • 10
  • 135
  • 204