diskutil list

This is my diskutil list.

I wish to merge Misc (disk0s4) with Macintosh HD (disk0s2) leaving only Macintosh HD (disk0s2). Normally I would use this command to merge the two disks:

diskutil mergePartitions HFS+ Macintosh HD disk0s2 disk0s4

But, I am not sure whether this command will format my Macintosh HD which I do not want. Misc (disk0s4) is already formatted and thus empty. But Macintosh HD (disk0s2) can not get erased.

Can I securely use the command to merge the two disks?

System information: OS X El Capitan, version 10.11.3

  • Perform First Aid, if at all anything goes wrong in the Disk Utility. Commented Nov 3, 2017 at 8:48

2 Answers 2

diskutil  erasevolume  "Free Space"  ""  /dev/disk0s4
diskutil  resizevolume  /dev/disk0s2  R

The first command will remove partition /dev/disk0s4.

The second command will move /dev/disk0s3 to the bottom of disk0 while resizing /dev/disk0s2 to maximum size.

  • For APFS partitions you must use: diskutil apfs resizeContainer disk0s2 limits to find the right sizes for resizing and use diskutil apfs resizeContainer disk0s2 <newSize> for actual resizing
    – youhans
    Commented Oct 5, 2018 at 6:56
  • @youhans: If disk0s2 was an APFS container and therefore no disk0s3, then the correct command would be diskutil apfs resizeContainer disk0s2 0. Commented Oct 5, 2018 at 9:09

The command diskutil mergePartitions HFS+ Name disk0sx disk0sy will merge all disk slices from disk0sx to disk0sy while only data on the first disk partition in the command (i.e. disk0sx) won't be erased. In your case disk0s2, disk0s3 and disk0s4 will be merged into disk0s2. Consequently you will lose your Recover HD partition.

If the volume name contains spaces use quotes: diskutil mergePartitions HFS+ "Macintosh HD" disk0s2 disk0s4.

I never had a problem merging slices like this but it's always beneficial to have a working (Time Machine) backup.

To recreate your Recovery HD after merging it to disk0s2 either reinstall your current system or use a tool like RecoveryPartitionCreator 3.8.

  • Okay, I am currently using time machine to make a backup to an external harddrive to make up for the lost recovery disk. After the merge, I assume I can make a new recovery partition? You reply answered my question completely. Thank you.
    – Emil_S
    Commented Apr 20, 2016 at 14:54
  • Would it be possible to change the identifier associated with "Recovery HD"? That is, if I changed Recovery HD from disk0s3 to disk0s5 the Recovery HD wouldn't be between the two slices disk0s2 and disk0s4.
    – Emil_S
    Commented Apr 20, 2016 at 14:54
  • @Emil_S Reinstalling your current system (e.g. 10.11.4) should rebuild the Recovery HD partition without touching your data. Depending on your setup RecoveryPartitionCreator 3.8 may also work.
    – klanomath
    Commented Apr 20, 2016 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .