Delete a Partition in macOS Using Terminal When Disk Utility Doesn’t Help

Mac OS X has a pretty solid disk utility for scenarios where you might want to create, resize or delete or modify new or existing partitions. However, in rare cases, the utility might not be as helpful as it should be and can leave your Mac’s SSD or hard drive in a mess.

Fix Partition Issues in Mac OS X When Disk Utility Doesn’t Help.jpg

Such an experience happened recently with yours turly. I had installed Windows 10 Insider Preview via Boot Camp on my MacBook Air but it stopped working due to an incomplete Windows Update. I decided to remove the installation from my Mac but the Boot Camp utility in OS X used to get stuck after a while when recovering the partition to the original size. Meanwhile, Disk Utility showed the space as reserved for Boot Camp but did not show or allow me to mount the drive so I could delete it and merge it with my OS X partition.

So, here I was, left with half of my disk space on my MacBook Air (I have the 128GB variant). From prior Windows experience, this reminded me to take the command line route, or Terminal, in case of Mac. A little research through Apple’s support documentation for the right OS X Terminal commands led me to the below solution.

How to delete a partition through macOS Terminal

In case you ever get stuck in a situation where you are unable to recover a partition on your Mac, follow the below steps:

  • Open up Terminal on your Mac
  • Type in the below command and press enter
    diskutil list
  • It should show you a list similar to the above screenshot. From here, you would have to select the partition you want to recover and erase it. Use the following command:
    diskutil eraseVolume JHFS+ drive /dev/disk0s4

    Here, instead of disk0s4, use the correct volume identifier as per the table you saw when you entered the list command. JHFS+ is short for Journaled Heirarchical File System Extended, or in a nutshell, the file system used by OS X. The volume being erased has to match the first volume’s file format else there would be unexpected data loss.

  • Once the volume is erased, you now have to merge the partitions. For this step, note that the first volume that you list in the command will gain the space from the second volume, effectively destroying any data in it. The first volume, in this case likely to be the OS X installation volume, will remain safe.
    diskutil mergePartitions JHFS+ NewName disk2s4 disk2s6

    Here, the command is to merge partitions, in the JHFS+ format, with a name (NewName as an example) and the volume identifiers, first and second volumes, respectively.

  • Let this command work and do its thing. After it’s done, you can re-run the diskutil list command again to verify that the volumes have merged and you have regained your space. You can also go to About This Mac > Storage or Disk Utility to double check.

Similarly, these commands can also be used to create, mount, unmount, rename partitions and do much more on your Mac. Type in diskutil in the Terminal and hit enter to see the complete list of supported commands.

If you require any help in the above steps, feel free to reach out to me via comments below or on Twitter.

About the Author

Technology enthusiast, Internet addict, photography fan, movie buff, music aficionado.