How to resize (grow) APFS partition that is at the end of the drive?

[new info below post] -- I'm having trouble resizing an APFS partition on the 240Gb SSD in my Mac. I want to make all space available to the system partition "Macintosh SSD".

Output of diskutil list:

/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *240.1 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_Boot Boot OS X               134.2 MB   disk0s2
   3:                 Apple_APFS Container disk1         81.9 GB    disk0s3

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +81.9 GB    disk1
                                 Physical Store disk0s3
   1:                APFS Volume Macintosh SSD           54.8 GB    disk1s1
   2:                APFS Volume Preboot                 44.7 MB    disk1s2
   3:                APFS Volume Recovery                509.5 MB   disk1s3
   4:                APFS Volume VM                      20.5 KB    disk1s4
   5:                APFS Volume Nieuw                   655.4 KB   disk1s5

I tried resizing the container, but this results in an error (see below). I believe due to the fact that the system partition is located at the end of the drive.

Mac-mini:~ admin$ diskutil apfs resizeContainer disk1 239g
Started APFS operation
Aligning grow delta to 157.073.416.192 bytes and targeting a new physical store size of 238.999.998.464 bytes
Determined the maximum size for the targeted physical store of this APFS Container to be 81.926.582.272 bytes
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

Can anyone help me how to add the free space to the "Macintosh SSD" partition?

Thanks, Koen

Update 1: Thanks for the quick response! Though, I got replies that it may be a duplicate with this post. I think it is not, because:
- I have no disk0s3 "storage" volume that may be blocking the space; and
- Running the command in step 3 in that post results in this error:

sh-3.2# diskutil apfs resizeContainer disk0s3 0
Started APFS operation
Error: -69743: The new size must be different than the existing size

Thanks again for any help, it is much appreciated.

Update 2: Output of diskutil info disk0s3 | grep -e "Partition Offset" -e "Disk Size" as requested by David Anderson:

   Partition Offset:          158130806784 Bytes (308849232 512-Byte-Device-Blocks)
   Disk Size:                 81.9 GB (81926582272 Bytes) (exactly 160012856 512-Byte-Units)

The command you are using adds any significant amount of free space immediately after the APFS container partition. By adding the values posted in your Update 2, you can see the APFS partition container is already at the end of the drive. There is no significant amount of free space to add.

  158,130,806,784 B
 + 81,926,582,272 B
 ------------------
  240,057,389,056 B = 240.1 GB

Below, I computed that there is 81.7 GB of free space somewhere above the APFS container partition. The macOS operation system offers no command or application that would add any of this free space to the APFS container partition.

  240.1 GB
    -.2 GB     
    -.1 GB  
 -158.1 GB
 ---------
   81.7 GB

The easiest solution would be to backup you files, erase the drive, reinstall macOS and reload your files.

Another more complex solution would be to create a new APFS container partition above the existing APFS container partition. You could then either:

  • Install macOS in the new APFS container partition, then use the Migration Assistant to copy all your files and applications. I have used this solution before.

OR

  • Attempt to clone the old APFS container partition to the new APFS container partition. I have never tried this solution. Maybe some else could comment or post an answer.

Afterwards, you could erase the old APFS container partition to create free space immediately after the new APFS container partition. You could then use the diskutil apfs resizeContainer command to add this new free space to the new APFS container partition

Creating new APFS container partition would involve several steps. Some of these steps would have to be preformed while booted to macOS Recovery. You should backup your files before attempting these steps. However, once you have a backup, you might as well just erase the entire drive and reinstall macOS. If want me to include the steps to create a new APFS container partition, then post a comment.