This is the Disk List for my iMac.
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
Best Answer
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 withgpt
and finally expand disk0s2 withdiskutil
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.
sudo
togpt ...
anddd ...
commands.Get an overview and check disk and volumes (repair if necessary) :
Remove disk0s2:
add a partition with the same size as disk0s3
copy disk0s4 to disk0s2:
merge disk0s2-disk0s4 and rename macOS 2 to macOS: