We’ve all been there. You installed Linux on your shiny Macbook Pro but now you’ve run out of space on your hard drive and lets be honest, you really haven’t used linux in the last year or two so you decide to go ahead and delete the linux partition on your hard drive to free up some space. What could go wrong?
You move on, you forget about that you even did this but the next time you reboot your Macbook, it boots to this screen!
Oh boy! You frantically type in words like “boot” or “mac” but it doesn’t really recognize any of those commands. In fact it mocks you by saying you need to load a kernel first.
Now if you are slightly technologically inclined, you must have said to yourself, lets just boot into Internet Recovery right? Just Command (⌘) and R into it, reinstall the OS over your existing installation and voila!
Well your mac boots into Internet Recovery and it doesn’t even recognize your internal drive. You fire up Terminal in Recovery mode and run
gpt -r show disk0
and you see this freaking oddity! That 2nd partition that has all your data is now is named FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF its looking more and more likely that you’ll have to wipe your hard drive and start all over.
The good news is that you won’t! See when you trashed that Linux partition a little while ago, you really screwed up your APFS container and your GPT partition table. Your data exists but your Macbook doesn’t really recognize that partition as valid. We’ll need to fix your GPT partition table in order for your Mac to recognize your macOS partition so we can boot into it.
So lets gather a few pieces of information from that terminal command we ran.
- Start: 409640 (Make sure you write down what you see on your screen – these numbers are from my machine)
- Size: 226802864
- Index: 2
Now that we that information we can delete the “bad” partition table entry with the “good” one that will let us boot back into macOS.
To begin, we unmount all partitions on disk0 (aka disk0s1, disk0s2, disk0s3)
diskutil unmountdisk /dev/disk0
Once we’ve unmounted all partition in disk0, we can begin by removing the bad entry in the GPT partition table. Use the index number you noted down earlier and use it in this command for the -i parameter. I’m using 2 since that was the index number of my macOS partition.
gpt remove -i 2 /dev/disk0
Now that we’ve removed it, we’ll add it back in with the correct parameters. Please note I’m using index number, start (-b) and size (-s) parameters from information I’ve gathered in my earlier command. My type of partition before this disaster was APFS (Apple File System) so I use that for the -t parameter.
gpt add -i 2 -b 409640 -s 226802864 -t apfs /dev/disk0
and voila! You should now have a functioning APFS container again.
To confirm run the following command to ensure you got rid of the FFFFF partition entry and the new one should have a unique GUID.
gpt -r show /dev/disk0
If everything looks good, simply reboot your machine and you should see the Apple logo instead of the GRUB terminal screen.