MacOS – Merge Partitions with Disk Utility in El Capitan Gives operation Failed error

disk-utilitymacos

I accidentally created a partition of 1.05GB space. Went to Disk Utility -> Partition, and I clicked on the – sign to remove it and hit "apply".

enter image description here
It gives me the following error:

enter image description here

I have another 40GB of free space partition after this 1GB partition that I want to merge with so can I get back to a single partition for an entire disk again. Any ideas how I could fix this?

diskutil list:

/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *251.0 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage Macintosh HD            195.6 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
   4:                  Apple_HFS Untitled                54.0 GB    disk0s4
/dev/disk1 (internal, virtual):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh HD           +195.2 GB   disk1
                                 Logical Volume on disk0s2
                                 D7989525-A492-467F-9631-6214317713EE
                                 Unlocked Encrypted

diskutil cs list

CoreStorage logical volume groups (1 found)
|
+-- Logical Volume Group E62C1353-2508-415A-BDC1-1EEAE65D9303
    =========================================================
    Name:         Macintosh HD
    Status:       Online
    Size:         195605651456 B (195.6 GB)
    Free Space:   11182080 B (11.2 MB)
    |
    +-< Physical Volume DEC475C0-94E9-4415-A6DC-AA7578AD239D
    |   ----------------------------------------------------
    |   Index:    0
    |   Disk:     disk0s2
    |   Status:   Online
    |   Size:     195605651456 B (195.6 GB)
    |
    +-> Logical Volume Family E7A40A0F-9D63-46DA-8E39-AF0CDCE8A39D
        ----------------------------------------------------------
        Encryption Type:         AES-XTS
        Encryption Status:       Unlocked
        Conversion Status:       Complete
        High Level Queries:      Fully Secure
        |                        Passphrase Required
        |                        Accepts New Users
        |                        Has Visible Users
        |                        Has Volume Key
        |
        +-> Logical Volume D7989525-A492-467F-9631-6214317713EE
            ---------------------------------------------------
            Disk:                  disk1
            Status:                Online
            Size (Total):          195242147840 B (195.2 GB)
            Revertible:            Yes (unlock and decryption required)
            Revert Status:         Reboot required
            LV Name:               Macintosh HD
            Volume Name:           Macintosh HD
            Content Hint:          Apple_HFS

sudo gpt -r show /dev/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  382042288      2  GPT part - 53746F72-6167-11AA-AA11-00306543ECAC
  382451928    1269536      3  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
  383721464     786432         
  384507896  105464672      4  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
  489972568     262151         
  490234719         32         Sec GPT table
  490234751          1         Sec GPT header

sudo fdisk /dev/disk0

Disk: /dev/disk0    geometry: 30515/255/63 [490234752 sectors]
Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 1: EE 1023 254  63 - 1023 254  63 [         1 -  490234751] <Unknown ID>
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused      

Best Answer

The Terminal application commands are shown below.

diskutil  erasevolume  "Free Space"  ""  /dev/disk0s4
diskutil  cs  resizestack  D7989525-A492-467F-9631-6214317713EE  0

The first command deletes your 54 GB Untitled partition. The second command merges all the free space back in to the other partition.