13

I have a Macbook Pro with retina, Yosemite and 500GB hard drive. I tried to install Windows using Bootcamp and accidentally deleted a partition, now my Mac cannot boot anymore. This is the output from sudo gpt -r show disk0

  gpt show: disk0: Suspicious MBR at sector 0
    start       size  index  contents
        0          1         MBR
        1          1         Pri GPT header
        2         32         Pri GPT table
       34          6         
       40     409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
   409640  776617328      2  GPT part - FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF
777026968    1269760      3  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
778296728        616         
778297344  198807552      4  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
977104896        131         
977105027         32         Sec GPT table
977105059          1         Sec GPT header

I only need to make the second partition at index 2 and type FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF to be bootable again. This partition has FileVault 2 enabled.

But right now, I have no clue on what to do.

P/S: I Followed the instruction from @klanomath Boot from a external hard drive with full Yosemite system but at the last command to change the partition type

sudo gpt add -b 409640 -s 776617328 -i 2 -t 53746F72-6167-11AA-AA11-00306543ECAC /dev/disk0

It got this error:

gpt add: /dev/disk0: Suspicious MBR at sector 0
gpt add: /dev/disk0: error: no space available on device

This is the output from sudo gpt -r show /dev/disk0

   gpt show: /dev/disk0: Suspicious MBR at sector 0
     start       size  index  contents
         0          1         MBR
         1          1         Pri GPT header
         2         32         Pri GPT table
        34          6         
        40     409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
    409640  776617328      2  MBR part 218
 777026968    1269760      3  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
 778296728        616         
 778297344  198807552      4  MBR part 175
 977104896        131         
 977105027         32         Sec GPT table
 977105059          1         Sec GPT header

Progress:

I have executed command sudo gpt destroy /dev/disk0

But when I tried to add the first partition back using this command sudo gpt add -b 40 -s 409600 -i 1 -t C12A7328-F81F-11D2-BA4B-00A0C93EC93B /dev/disk0

I got this error straight away

gpt add: /dev/disk0: Suspicious MBR at sector 0
gpt add: /dev/disk0: error: no primary GPT header; run create or recover

Now the command sudo gpt -r show /dev/disk0 gives me this

   gpt show: /dev/disk0: Suspicious MBR at sector 0
     start       size  index  contents
         0          1         MBR
         1     409639         
    409640  776617328      2  MBR part 218
 777026968    1269760      3  MBR part 175
 778296728        616         
 778297344  198807552      4  MBR part 175
 977104896        164

Progress 2:

I executed sudo gpt create /dev/disk0 and got this error:

gpt create: /dev/disk0: Suspicious MBR at sector 0
gpt create: /dev/disk0: error: device contains a MBR

and I executed this command sudo fdisk -i -a hfs /dev/disk0 to write new MBR and executed sudo gpt create /dev/disk0 again but got the same error gpt create: /dev/disk0: error: device contains a MBR

Now sudo gpt -r show /dev/disk0 gives me this

      start       size  index  contents
      0          1         MBR
      1         62         
     63  977104997      1  MBR part 175

Progress 3 and final :D

Firstly a big thank to @klanomath, without the help, I couldn't go this far.

I executed this command sudo gpt create -fp /dev/disk0

And this command sudo gpt recover /dev/disk0 to get the secondary GPT header

After that, I executed sudo gdisk /dev/disk0 and the disk is mounted and functions properly

1
  • I have to issue a protest here. The very last command you issued in your answer is sudo gdisk /dev/disk0, which is an interactive command. You have failed to specify the commands you entered into gdisk. Also, since your partition problems can be fixed by just entering commands into gdisk, then all the commands you posted before entering sudo gdisk /dev/disk0 were unnecessary and did not need to be entered. Commented Apr 21, 2022 at 18:58

2 Answers 2

14

The content type of the second partition is wrong. Instead of FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF it has to be 53746F72-6167-11AA-AA11-00306543ECAC.

To edit the content type you have to boot to Internet Recovery Mode and use gpt. Additionally the fourth partition will be removed (probably the "deleted" partition). Please check that it doesn't contain any data!

Preparation:

  • Detach any external drive (especially your external Time Machine backup drive)
  • Restart to Internet Recovery Mode by pressing alt cmd R at startup.

The prerequisites are the latest firmware update installed, either ethernet or WLAN (WPA/WPA2) and a router with DHCP activated.
On a 50 Mbps-line it takes about 4 min (presenting a small animated globe) to boot into a recovery netboot image which usually is loaded from an Apple/Akamai server.

I recommend ethernet because it's more reliable. If you are restricted to WIFI and the boot process fails, just restart your Mac until you succeed booting.

Alternatively you may start from a bootable installer thumb drive (preferably Yosemite or El Capitan) or a thumb drive containing a full system (preferably Yosemite or El Capitan). If you boot to a full system and login as admin you have to prepend sudo to execute special commands like gpt ...!

Remove the fourth partition and change the content type of the second partition

  • Booted to Internet Recovery Mode open Utilities → Terminal in the menubar and enter: diskutil list to get the disk identifiers. Below I assume that your main disk has the disk identifiers disk0.

  • First you have to remove the fourth partition (only do that if it is really empty!):

      gpt -r show /dev/disk0 #to get an overview
    

To delete a partition with gpt the disk has to be unmounted:

    diskutil unmountDisk /dev/disk0
    gpt remove -i 4 /dev/disk0 #remove the fourth partition
  • Then you have to change the content type of the second partition:

      diskutil unmountDisk /dev/disk0
      gpt remove -i 2 /dev/disk0 #remove the second partition
      gpt add -b StartBlock -s NumberOfBlocks -i 2 -t 53746F72-6167-11AA-AA11-00306543ECAC
    

In your case:

    gpt add -b 409640 -s 776617328 -i 2 -t 53746F72-6167-11AA-AA11-00306543ECAC /dev/disk0
  • Now you should be asked for the FileVault passphrase. Enter it.
  • Enter exit and quit Terminal
  • Check the main volume Macintosh HD for errors
  • Quit Disk Utility and reboot to your main volume

Addendum: Removing the stubborn MBR

You can either use fdisk or gpt to remove the MBR at block 0. If you use an admin user prepend sudo using the gpt .... and dd .... commands.

  • First get an overview again. This step is important before you destroy the gpt, because it's the source to rebuild it from scratch:

      gpt -r show /dev/disk0
    
  • Then delete the gpt:

      diskutil unmountDisk /dev/disk0
      gpt destroy /dev/disk0
    
  • Overwrite the MBR with zeroes:

      diskutil unmountDisk /dev/disk0
      dd if=/dev/zero count=1 of=/dev/disk0
    
  • Create new MBR and GUID partition tables:

      gpt create -f /dev/disk0
    
  • Finally add all partitions one by one:

      gpt add -b 40 -s 409600 -i 1 -t C12A7328-F81F-11D2-BA4B-00A0C93EC93B /dev/disk0
      gpt add -b 777026968 -s 1269760 -i 3 -t 426F6F74-0000-11AA-AA11-00306543ECAC /dev/disk0
      gpt add -b 409640 -s 776617328 -i 2 -t 53746F72-6167-11AA-AA11-00306543ECAC /dev/disk0
    

Hint: You may add and remove partitions in an arbitrary order if you keep the right index number. In the above commands I added the third partition (... -i 3 ...) before adding the second partition (... -i 2 ...). You don't have to unmount disk0 then because the partitions i=1 and i=3 don't contain auto-mounted volumes while the second partition does.

I missed to detect the wrong partition type of your Recovery HD (the third partition with the index number 3) in the first part of my answer. Therefore I used:

    gpt add -b 777026968 -s 1269760 -i 3 -t 426F6F74-0000-11AA-AA11-00306543ECAC /dev/disk0

above instead of the wrong

    gpt add -b 777026968 -s 1269760 -i 3 -t 48465300-0000-11AA-AA11-00306543ECAC /dev/disk0 #wrong partition type of the Recovery HD

to re-add it.


An alternative, to entering the diskutil unmountDisk /dev/disk0 command give above, would be to enter the commands given below.

    fdisk -i -a hfs /dev/disk0
    gpt create -fp /dev/disk0 

However this sequence of commands relies on undocumented behavior of the gpt create -fp /dev/disk0 command and therefore should be avoided.


Resizing the main volume to fill the whole disk

Finally you probably want to resize the main volume to fill the whole disk.

  • Get an overview with:

      diskutil cs list
    

You may have several CoreStorage Logical Volume Groups, if you boot from an external drive with a full system! Use the proper one!

  • Resize the whole stack:

      diskutil cs resizeStack lvUUID size #lvUUID is the UUID of the Logical Volume. Usually it's the last one listed.
    

Booted to Yosemite you can use 0g for the size to expand it. 0g is a "magical" size here.

    diskutil cs resizeStack lvUUID 0g

Booted to El Capitan you have to use a real size like 500g. If you get an error use a slightly smaller size like 499g or499500m.

    diskutil cs resizeStack lvUUID 500g
7
  • 1
    I'm still stuck. Firstly, after executing "gpt delete -i 2 /dev/disk0", it said "gpt: unknown command: delete" so I assume that I need to change 'delete' to 'remove'. But at the last command that I need to execute, it said "gpt add: /dev/disk0: error: no space available on device"
    – L N
    Commented Dec 28, 2015 at 1:27
  • I have followed your instruction and posted the results in the question, thanks
    – L N
    Commented Dec 28, 2015 at 1:48
  • I have followed the second instruction, unfortunately I'm stuck again with the error "gpt add: /dev/disk0: error: no primary GPT header; run create or recover". I have added the progress
    – L N
    Commented Dec 28, 2015 at 6:33
  • no worries, I just updated my progress. looks like I couldn't get rid of the MBR
    – L N
    Commented Dec 28, 2015 at 6:47
  • 1
    Well that would've been useful to know when this same exact problem happened to me a few months ago...klanomath never fails to amaze me with how much he knows about macs. I ended up losing all my data.
    – Flare Cat
    Commented Jun 9, 2016 at 1:32
0

I'm not exactly answering the question but hoping this will help someone else. It was a 100G 7200rpm drive that had been mirrored from a 120G SSD, and then it suddenly became unreadable.

I followed everything here to the best of my abilities but was unsuccessful. I spent in excess of 30 hours trying. I had made a dd of it first so I was able to much around on a copy.

After realising that I was in trouble, I found a demo copy of UFS Explorer Professional, which showed me all my files were still there somewhere but to recover them needed US$600 or something which I am in not in a position to pay. This then somehow led me to find another app.

Raise Data Recovery was an app that I found that was affordable and does one thing - recover from HFS. It was able to return all my files in the correct directories to another drive. For some reason on my mac it kept dropping out destination during recovery, so I installed it on my Win10 on Parallels and it worked well. The license covers use on Windows, Mac and Linux. Raise DR seems to be Ukrainian as well so really happy to pay for something of such good quality and it saved my bacon. https://www.raisedr.com is the URL.

Anyway hoping this will help someone.

2

You must log in to answer this question.

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