Apple - How do I delete a BootCamp partition using Terminal's diskutil?

Here's what worked for me:

  1. use diskutil list to find the small Microsoft Reserved partition you're trying to delete but disk utility (or the command-line equivalent diskutil) won't allow. Let's say it's on disk 99 partition 400 (mine was on disk 0 partition 4)
  2. sudo diskutil eraseVolume JHFS+ deleteme /dev/disk99s400

The above reformats the partition to journaled HFS+ and once you've done that you can just simply delete it (and then resize etc. as you wish).

Note: I've used /dev/disk99s400 because that should not ever work, you have to replace those with the right disk and partition.

WARNING: Destructive, high risk. ALWAYS do a full back up first before screwing with partitions. ALWAYS.


Have you tried booting from OSX installation media? Those have both a Terminal (with diskutil) and the GUI Disk Utility, which might start working as you're no longer trying to partition the drive you're booting from.

Caution, from now on: here be dragons! Make sure you understand what's going on before you start on this, you can't back out halfway! Check your backups are readable!

If both versions of diskutil fail here too, stay in the installation media's terminal and get the raw partition table using:

gpt -r show disk0

What has likely happened is that the two partition tables, the GPT and the MBR, have gone out of sync. This happens if you try to partition your Mac disk from Windows. The above shows the GPT version (which OSX uses). This shows the MBR version (which Windows uses):

fdisk /dev/disk0

Make sure this is the disk you want to change (might be disk1, disk2, etc). Note the number (index) of the partition you want to delete in both the GPT and the MBR. They might not be the same!

If confused, post the output from the above 2 here, and don't proceed.

Unmount all mounted partitions on the disk you want to partition, e.g.

diskutil unmount "/Volumes/Macintosh HD"
diskutil unmount "/Volumes/BOOTCAMP"

Then comes the dangerous bit (make sure you have backups): Delete the partition using the gpt utility:

gpt remove -i 4 disk0

Make sure to substitute the index of the partition to delete (IN THE GPT) instead of "4" and the exact disk you're partitioning instead of "disk0"!

Finally, you'll need to delete the same partition from the MBR (you may need to unmount again at this point).

Option 1: Remove all trace of bootcamp (only boot OSX on this disk)

If you want to completely remove any trace of Boot Camp (no OSes other than Mac OS X) you can completely destroy the MBR partition table and replace it with a so-called "protective MBR":

fdisk -e /dev/disk0

This lands you at the fdisk command line - the parts in bold are what you type.

fdisk: 1>p

This will show your partition table, same as earlier. You want to replace it with a single protective partition of type EE, covering the whole disk.

fdisk: 1>erase

fdisk:*1>edit 1

Partition id ('0' to disable) [0 - FF]: [0] (? for help)EE

Do you wish to edit in CHS mode? [n]n

Partition offset [0 - 505856]: [63]1

Partition size [1 - 505855]: [505855] (just press enter here to go with the default - the exact number will depend on your disk size)

fdisk: 1>p

This should now show a partition table with the first entry of type EE, and the remaining 3 entries blank.

fdisk: 1>w

Writes your changes to disk. You'll need to quit out of fdisk with

fdisk: 1>q

Next: reboot and pray.

Option 2: Remove only the affected partition (go from triple boot to dual boot or so)

If you want to keep the hybrid MBR, just not the one partition, begin editing the MBR like so:

fdisk -e /dev/disk0

This lands you at the fdisk command line - the parts in bold are what you type.

fdisk: 1>p

This will show your partition table, same as earlier.

Find the entry that corresponds to the partition you're deleting, e.g. 4, then edit that entry (replace "4" with your entry):

fdisk:*1>edit 4

Partition id ('0' to disable) [0 - FF]: [7] (? for help)0

Partition 4 is disabled.

fdisk: 1>p

This should now show a partition table with the deleted partition missing.

fdisk: 1>w

Writes your changes to disk. You'll need to quit out of fdisk with

fdisk: 1>q

Next: reboot and pray.


The answer is to boot off the recovery HD partition, use disk until and select the Bootcamp partition. Then on the erase tab select the format and change it to Mac OS Extended journaled. Now you can erase the drive.