1

I accidentally formatted my SSD's GPT while formatting a USB in Linux's gparted. Now, when running gpt in Mac's command line, this is how my SSD looks like:

My-MacBook-Pro:~ user$ sudo gpt -r show disk2
       start        size  index  contents
           0           1         PMBR
           1           1         Pri GPT header
           2          32         Pri GPT table
          34  1000215149         
  1000215183          32         Sec GPT table
  1000215215           1         Sec GPT header

I used to have 2 partitions on this drive: Mac OSX and a Windows 8.1 bootcamp partition. I wouldn't mind loosing the latter.

I have heard about being able to restore the partition with the gpt command in Mac. Is this possible in my case?

Thanks, Martin

  • Do you happen to know how big your Windows 8.1 or your Mac OS X partition was? – klanomath Mar 6 '15 at 9:05
1

If you don't want to use Disk Warrior or something similar to get your volumes back, there is a small chance to recover your partitions manually:

You'll need some tools and luck to accomplish that:

Install a full vanilla system (Mountain Lion or Mavericks should work) on a thumb drive. A recovery system will not work. Boot to the thumb drive, download and install wxHexEditor. Enable the root user and log-in as root.

A classical partition map of Mountain Lion without any Boot Camp partition would probably look like this on your Mac:

sudo gpt -r show disk2
      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   998536000      2  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
  998945640     1269536      3  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
 1000215176           7 
 1000215183          32         Sec GPT table
 1000215215           1         Sec GPT header

A partition map of Mountain Lion with a Boot Camp partition would probably look like this (sizes may vary in your case - i have chosen a ~50 GB partition for Windows):

sudo gpt -r show disk2
      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   898536000      2  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
  898945640     1269536      3  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
  900215176      204800      4  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
  900419976    99795200      5  GPT part - EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
 1000215176           7 
 1000215183          32         Sec GPT table
 1000215215           1         Sec GPT header

Now we try to search for a specific text string of your Recovery HD-partition on your disk. In the example above this is the partition with index number 3.

Open wxHexEditor. In the menubar go to "Devices" -> "Open disk device" -> choose the appropriate diskNummber. Probably it's disk1 or disk2. The disk shouldn't have any further partitions like disk1s1 or disk1s2. Try to arrange the windows like in the example below with straight red lines and scroll to the very end of the disk (your visible offset number is approx. 51211000000):

wxHexEditor

Now hit the search button and enter manually:

/private/var/tmp/efiboot/efiboot

and enable "Text Search", "Match Case" and "Search Backwards" like in the example below:

wxHexEditor

This may take a while. Please check the position of the scrollbar indicator if the finding is realistic. If you've split your disc in 375 GB (Mac OS X) and 125 GB (Windows) then the string match should be at the beginning of the 4th quarter.

Make a note of the first offset number of the block containing the string.

Additionally scroll to lower offset numbers. It should be filled with zeros except the block directly preceding. If you find anything else than zeroes stop here.

  • In my example it's 68195037696. Divide that number through 512 to get its block number: 68195037696/512 = 133193433

Remove 244921 from the number found above to get the starting block of your Recovery HD.

  • In my example 133193433 - 244921 = 132948512.

Remove 1 from the number found above to get the ending block of your main volume.

  • In my example 132948512 - 1 = 132948511 (*)

With the starting block of the Recovery HD found, we may now add the different missing partitions:

You may have to unmount the device with:

diskutil unmountDisk diskNumber

(with the diskNumber you found above: probably disk1 or disk2)

First we recover the EFI partition by entering:

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

(with the diskNumber found above: probably disk1 or disk2)

Then we recover your main partition by entering:

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

(with SizeOfPartition = (*) - 409640 +1)

In my example that would be: 132948511 - 409640 + 1 = 132538872

Then we recover your Recovery HD by entering:

gpt add -b EndblockOfMainVolume+1 -i 3 -s 1269536 -t 426F6F74-0000-11AA-AA11-00306543ECAC diskNumber

Then you may label all the partitions with gpt label -i IndexNumber -l "Name" diskNumber:

gpt label -i 1 -l "EFI" diskNumber
gpt label -i 2 -l "Macintosh HD" diskNumber
gpt label -i 3 -l "Recovery HD" diskNumber

(with the diskNumber found above: probably disk1 or disk2)

Now restart your Mac to the thumb drive again. Open disk utility and check the restored volume for errors.

If everything is fine, backup the content of your main volume, partition the SSD, reinstall Mac OS X Mountain Lion and migrate your apps and users.

Good luck to recover your disk - i hope it works like that. If you are unsure or have any questions leave a comment here starting with @klanomath

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .