Resizing a partition on El Capitan 10.11.6? I want to remove both disk0s4 and disk0s5 partitions which were created for a bootcamp install. However when I goto disk utility then try to remove the partitions from my drive, I get the following error: MediaKit reports not enough space on device for requested operation.

Screenshots below:





Here is what I get when I run diskutil list

/dev/disk0 (internal, physical):
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      GUID_partition_scheme                        *500.1 GB   disk0
1:                        EFI EFI                     209.7 MB   disk0s1
2:                  Apple_HFS Macintosh HD            425.6 GB   disk0s2
3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
4:                  Apple_HFS Untitled                73.4 GB    disk0s4
5:         Microsoft Reserved                         16.8 MB    disk0s5


After I run the command sudo gpt -r show disk0 :

      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  831297360      2  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
 831707000    1269536      3  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
 832976536  143274344      4  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
 976250880     262144         
 976513024      32768      5  GPT part - E3C9E316-0B5C-4DB8-817D-F92DF00215AE
 976545792     227343         
 976773135         32         Sec GPT table
 976773167          1         Sec GPT header


I would like to keep all data currently on the Macintosh HD, if someone could help me remove the untitled and microsoft reserved partitions, that would be great, thanks.
The command below should remove disk0s5.

sudo diskutil erasevolume "Free Space" "" /dev/disk0s5


The command below should remove disk0s4.

sudo diskutil erasevolume "Free Space" "" /dev/disk0s4


The next command expands your Macintosh HD volume (disk0s2) to contain the free space. This command will also automatically move the Recovery HD volume (disk0s3) to the end of the drive.

sudo diskutil resizevolume /dev/disk0s2 R



  Note: I am not sure if the prefix sudo is necessary. (But, it will do no harm if you include the sudo)


There are more complex steps that can be employed to remedy your problem, but I will not post these steps unless the one of the commands given above fails to work.