This is the Disk List for my iMac.

enter image description here

I am trying to merge the partitions macOS and macOS 2 using diskutil mergePartitions now the problem is on running this command macOS will keep data on the first partition which is macOS and will erase everything in between the first and last partition (Last partition included), now the last partition is macOS 2.

I want to preserve the last partition which is macOS 2 and delete every other partition so I thought why not include the last partition as the first partition (Which I want to preserve the data on) and include the first partition in the last parameter - which will be deleted.

Here's where the issue occurs macOS doesn't allows me to change the sequence of the partition

So I am stuck with merging partitions from command line

I don't want to use disk utility to merge partitions cause last time when I used it to merge partitions some free spaces were created and were not going away until and unless an entire disk format was performed!

One more thing macOS is the first volume on the disk so removing it from dusk utility using the partition option will not happen


You can't expand disk0s4 to lower blocks numbers with on-board tools! To "expand" disk0s4 you would have to remove disk0s2 , add a new partition with the same size and type as disk0s4 directly following disk0s1 all with gpt, dd disk0s4 to disk0s2, delete disk0s3 and disk0s4 with gpt and finally expand disk0s2 with diskutil into the unallocated space between disk0s2 and disk0s5.

Instead of the last two steps you can also use the diskutil mergePartitions ... command.

All that booted either in Internet Recovery Mode or an external drive with macOS installed.

  • Boot to Internet Recovery Mode or an external boot drive (if you aren't superuser you have to prepend sudo to gpt ... and dd ... commands.
  • Get an overview and check disk and volumes (repair if necessary) :

    diskutil verifyDisk disk0
    diskutil verifyVolume disk0s2
    diskutil verifyVolume disk0s4
    diskutil list
    gpt -r show disk0
  • Remove disk0s2:

    diskutil umountDisk disk0
    gpt remove -i 2 disk0
  • add a partition with the same size as disk0s3

    diskutil umountDisk disk0
    gpt add -i 2 -b 409640 -s 485642672 -t 48465300-0000-11AA-AA11-00306543ECAC disk0
  • copy disk0s4 to disk0s2:

    diskutil umountDisk disk0
    dd if=/dev/disk0s4 of=/dev/disk0s2 bs=4m
  • merge disk0s2-disk0s4 and rename macOS 2 to macOS:

    diskutil mergePartitions HFS+ "macOS" disk0s2 disk0s4 
  • I will paste the output of the gpt command in order to understand the steps better. I am confused and I don't want to delete anything in confusion! – Sayan Dec 6 '17 at 20:24
  • Please paste it as text (not as screenshot)! – klanomath Dec 6 '17 at 20:26
  • Here's the output pastebin.com/ud17Ribf – Sayan Dec 6 '17 at 20:43
  • After all the merging when I booted into the OS I am being greeted with a groups icon and a blank username and password dialogue box I don't know what to input! – Sayan Dec 7 '17 at 6:55
  • Your old user name and password from macOS 2?! – klanomath Dec 7 '17 at 6:57

Since the volumes are about the same size, you can use the Disk Utility application to "Restore" the macOS volume from the macOS 2 volume. You basically will then have duplicated macOS 2. You then can delete disk0s4 and expand disk0s2 to recover the free space.

All these operations can be performed using the Disk Utility application.

If you are wish to use the command line, then here is the command to clone the volume labeled "macOS 2".

sudo asr restore --source "/Volumes/macOS 2" --target /Volumes/macOS --erase

Note: The above command also clones /dev/disk0s5 to /dev/disk0s3.

The command to delete /dev/disk0s4 and expand /dev/disk0s2 is given below.

diskutil mergePartitions FREE "" disk0s2 disk0s4  

Note: The above command also deletes /dev/disk0s5 and relocates /dev/disk0s3 to be below the expanded /dev/disk0s2.

The clone/restore operation could be done while booted from /dev/disk0s5. The merge operation could be done while booted to /dev/disk0s2.

  • I would very much like to know how to do this from within Disk Utility itself. I don't see any obvious way beyond creating a disk image of the second volume and restoring it to the first. – JVC May 22 '18 at 2:41
  • Never mind, once I booted in recovery mode I see that you can restore to one partition directly from another. Very cool! – JVC May 22 '18 at 2:49

You must log in to answer this question.

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