Merge partitions with Macintosh HD
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
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.
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.