How to increase the size of the system partition (container) on Catalina

apfscatalinadisk-utilitypartition

This is on a Macbook Pro with a 250 GB disk that was originally split into two partitions, roughly 90 (Macintosh HD) and 160 GB (disk2). The machine is now on Catalina with the first partition being APFS and the second staying HFS. There is not enough space on the first partition and I am trying to add more space from the second to the first by following this guide:
https://www.macobserver.com/tips/deep-dive/resize-your-apfs-container/

After splitting the second partition into 2 with Disk Utility, I have an empty partition of 20GB that I convert to empty space by doing

sudo diskutil eraseVolume "Free Space" %noformat% /dev/disk0sX

as shown in the guide (on my system X is 5, not 3 as in the guide but this should not make any difference). Then when I try to resize the APFS container as shown in the guide by doing

diskutil apfs resizeContainer disk0s2 0

it gives me

Started APFS operation.
Error: -69519: The target disk is too small for this operation, or a gap is required in your partition map which is missing or too
small, which is often caused by an attempt to grow a partition beyond
the beginning of another partition or beyond the end of partition map
usable space

disk0s2 seems to be the correct disk as shown in diskutil list

...
 2:                 Apple_APFS Container disk1         89.5 GB    disk0s2
...

Any ideas whether what I am trying to achieve is even possible and if it is, how to do it?

Conclusion: I went with the second suggestion by David Anderson and it seems fine. The only thing that I noticed is that the high-level folders in disk2 are owned by root after copying them back, but that doesn't seem to be an issue.

As always, make sure that you have reliable backup of your system before doing this

Best Answer

If you shrunk the second (visible) partition to create free space. The free space is directly below this partition. You can not add this space to the APFS container, because the free space is not adjacent to the APFS container. In other words, the partition with the HFS volume is between the APFS container and the free space. This prevents adding the free space to the APFS container.

One possible solution would be the following.

  1. Move all the files from the HFS volume to an external drive.
  2. Convert the partition containing the HFS volume to free space.
  3. Add all the free space to the APFS container.
  4. Shrink the APFS container and add a new HFS volume.
  5. Move the files from the external drive to the HFS volume.

Another possibly better solution would be to replace partition with the HFS volume with a new APFS volume inside the existing APFS container. The steps are given below.

  1. Move all the files from the HFS volume to an external drive.
  2. Convert the partition containing the HFS volume to free space.
  3. Add all the free space to the APFS container.
  4. Add a new APFS volume to the APFS container.
  5. Move the files from the external drive to the new APFS volume.

The external drive would not have to be a HDD or SSD. You could use a 256 GB flash drive (or maybe a smaller flash drive).