Diskutil moving partitions into order for merging

disk-utilitydiskutilpartition

I just had my first attempt with diskutil mergePartitions – it was on a backup disk and I ended up loosing all partitions in between :p

Having learnt from my mistake that mergePartitions merges from the first partition to ALL IN BETWEEN up to the last – how can i move partitions so that they are in sequence.

So for example, say I have:

mergeThis   disk0s1
leaveAlone  disk0s2
leaveAlone  disk0s3
withThis    disk0s4

I want to merge disk0s1 with disk0s4, so how do I get to the following stage, before I can run the merge command

mergeThis   disk0s1
withThis    disk0s2
leaveAlone  disk0s3
leaveAlone  disk0s4

Any help would be appreciated.

Best Answer

Though you can't move the partitions, you will be able to merge both partitions. You have to convert disk0s1 to a CoreStorage Logical Volume Group, then add disk0s4 as a second CS Physical Volume to the existing CS LVG and expand the Logical Volume in the existing CS LVG to the expanded CS LVG. CS is available in older OS X versions but adding PV to existing LVG is only working reliably in OS X 10.9 and newer.

mergeThis   disk0s1
leaveAlone  disk0s2
leaveAlone  disk0s3
withThis    disk0s4

mergeThis   disk0s1 > LVG' > PV1 (disk0s1) > LVF' > LV' (disk1)
leaveAlone  disk0s2
leaveAlone  disk0s3
withThis    disk0s4

mergeThis   disk0s1 > LVG > PV1 (disk0s1) > LVF' > LV' (disk1)
leaveAlone  disk0s2
leaveAlone  disk0s3
withThis    disk0s4 > LVG > PV2 (disk0s4)

mergeThis   disk0s1 > LVG > PV1 (disk0s1) > LVF > LV (disk1)
leaveAlone  disk0s2
leaveAlone  disk0s3
withThis    disk0s4 > LVG > PV2 (disk0s4) > LVF > LV (disk1)

The content of disk0s4 will be erased. The content of disk0s1 will be preserved as disk1 and disk1 has finally the ~size of disk0s1 + disk0s4.


CoreStorage is a logical volume manager, which is an additional layer between device/partition and a volume.

A Logical Volume Group is based on one or several Physical Volumes (which can be one or several physical devices/partitions) and may contain one or several Logical Volume Families/Logical Volumes.

In OS X it's usually used to manage FileVault and Fusion Drives,