I deleted my Bootcamp partition but can't resize my OS X partition

Solution 1:

Quick fix: Fake Bootcamp.

"I partitioned the free space (that OS X couldn't use) as MS-DOS, Bootcamp Assistant thought it was Windows, and was able to remove this MS-DOS partition and restore Mac OS to a single partition."

This is the easiest solution, so try that first.

No luck? Long fix:

In my case, I couldn't get Disk Utility to create the partition.

I tried using gpt to recreate the partition, but it wouldn't write to the GPT while any of the partitions were mounted. But since it's my boot partition we're talking about, the disk was in use, because one of the partitions (my boot partition!) is mounted. So we need to boot from not-this-disk, and unmount all the partitions on the disk, and then use gpt.

Internet Recovery

Boot to Internet Recovery (hold Cmd+Opt+R during startup), so that the disk will not be in use. If your machine is too old for Internet Recovery, you should be able to boot from another disk (not another partition) and get the same result. Note: in this case that the disk numbers (/dev/disk0) may be different for you.

Start Internet Recovery, and go to Utilities -> Terminal.

Internet Recovery terminal

-bash-3.2# gpt show /dev/disk0

gpt show my former bootcamp partition

This is the space I want to reclaim.

As a sanity check, take the size (second column), multiply it by 512, and divide by a billion. The result should match the size of your former Bootcamp partition in GB.

Example: 58593759 * 512 / 1,000,000,000 = 30 GB

Take the start position (first column), that's where we'll tell gpt to make the new partition, with

gpt add -b <start position> -t windows /dev/disk0

In my case, you can see that the start position is 431640960. You can and should select/Copy/Paste in your own Terminal to get this number copied correctly.

Example: -bash-3.2# gpt add -b 431640960 -t windows /dev/disk0

/dev/disk0s4 added

Finally!

If you got an error No such file or directory, read the next section, and then come back here and try again.

Assuming you got the disk added ok, reboot and use Disk Utility to erase the new partition as MS-DOS. Run Bootcamp assistant and choose Remove Windows 7.

Bootcamp has been removed and your disk has been restored to a single volume.

And all it took was my whole day.

unable to open device '/dev/disk0': No such file or directory

When you use the gpt add command, you might get the error

unable to open device '/dev/disk0': No such file or directory

This message is very confusing. We just read that device earlier with gpt show. This message really means "device is in use".

OS X Recovery may have mounted it, and you have to unmount it. Use the mount command to find your mounted partition and umount it.

-bash-3.2# mount

will produce a huge list of partitions:

/dev/disk2s3 on /
devfs on /dev
/dev/disk3 on /Volumes
/dev/disk4 on /private/var/tmp
/dev/disk5 on /private/var/run
/dev/disk6 on /System/Installation
/dev/disk7 on /private/var/db
/dev/disk8 on /private/var/folders
/dev/disk9 on /private/var/root/Library
/dev/disk10 on /Library/ColorSync/Profiles/Displays
/dev/disk11 on /Library/Preferences
/dev/disk12 on /Library/Preferences/SystemConfiguration
/dev/disk13 on /Library/Keychains
/dev/disk1 /Volumes/Macintosh HD  <--- unmount this /Volumes/<YourDisk>

-bash-3.2# umount /dev/disk1

It will periodically be remounted automatically, so try to hurry or you'll have to unmount it again.