Can't reclaim empty space on main macOS partition [macOS Mojave]

A while ago I made a linux partition on my MBP (2017), but it didn't work so well so I needed to delete the partition. After a lot of trouble trying to delete it, I found this answer; I used the second part to free the space on the old linux partition, and then I resized it to 0. Only, it didn't actually resize. The partition is still there (though it is no longer showing up in Disk Utility):

$ diskutil list
/dev/disk0 (internal):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                         500.3 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         276.5 GB   disk0s2
   3:                        EFI NO NAME                 629.1 MB   disk0s3

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +276.5 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            246.9 GB   disk1s1
   2:                APFS Volume Preboot                 45.9 MB    disk1s2
   3:                APFS Volume Recovery                510.8 MB   disk1s3
   4:                APFS Volume VM                      1.1 GB     disk1s4

I think it is this line that is the culprit, though I am not sure:

   2:                 Apple_APFS Container disk1         276.5 GB   disk0s2

As I say, I have run

diskutil apfs resizeContainer disk0s2 0

As per the linked answer, but nothing changed. Even in recovery mode, Disk Utility will only show the ~277 GB I have available on the main partition.

How can I reclaim this space, which is no longer actually showing up?


P.S., this is what I had before I ran those commands:

$ diskutil list
/dev/disk0 (internal):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                         500.3 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         276.5 GB   disk0s2
   3:                        EFI NO NAME                 629.1 MB   disk0s3
   4:                  Apple_HFS Untitled                222.7 GB   disk0s4
   5:                 Apple_Boot Boot OS X               134.2 MB   disk0s5

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +276.5 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            249.7 GB   disk1s1
   2:                APFS Volume Preboot                 45.9 MB    disk1s2
   3:                APFS Volume Recovery                510.8 MB   disk1s3
   4:                APFS Volume VM                      6.4 GB     disk1s4

/dev/disk3 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            NO NAME                +10.7 GB    disk3

NO NAME was just a USB drive, by the way.


You need to first remove the second EFI partition. Enter the commands given below.

diskutil erasevolume free none disk0s3
diskutil apfs resizeContainer disk0s2 0

Explanation:

The disk0s3 slice occurs after the disk0s2 slice. The free space exists after the disk0s3 slice. The command diskutil erasevolume free none disk0s3 will remove the disk0s3 slice from the partition table, thus increase the size of the free space. The diskutil apfs resizeContainer disk0s2 0 command can then be used to add the free space to the disk0s2 slice. In other words, disk0s3 is in the way and is preventing you from adding the free space to disk0s2.