Resizing APFS container and partition

I was tring to increaze the size of the Windows 10 Boot Camp partition with Disk Utility but I made a mess. I decreased the Mac partition with Disk Utility which created a new partition.

After that I wasn't able to boot in Windows 10 anymore. Now Disk Utility can see only half of my 1 TB hard drive.

I can't make bigger the container of 498 GB and reinstall Windows 10 with Boot Camp!

Pupo-MacBook-Pro:~ max$ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_APFS Container disk1         498.9 GB   disk0s2
   3:                 Apple_Boot Boot OS X               134.2 MB   disk0s3
   4:                 Apple_Boot Boot OS X               134.2 MB   disk0s4

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +498.9 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Mac                     76.1 GB    disk1s1
   2:                APFS Volume Preboot                 23.2 MB    disk1s2
   3:                APFS Volume Recovery                507.4 MB   disk1s3
   4:                APFS Volume VM                      4.3 GB     disk1s4

In a YouTube video I understand in Mojave I have to use something like this to resize:

sudo diskutil apfs resizeContainer disk1 / R
sudo diskutil resizeVolume / R

but it didn't work!

I'm a newby, no experience at all. first time I open Terminal on Mac! Does anyone can help?


Solution 1:

Try the commands given below.

sudo diskutil eraseVolume free none disk0s4
sudo diskutil eraseVolume free none disk0s3
sudo diskutil apfs resizeContainer disk0s2 0

The partitions with the identifiers disk0s3 and disk0s4 are of the type used for (pre)boot and/or recovery volumes. I assume these partitions are left over from some previous macOS installation(s). You no longer need these partitions since the APFS container has both (pre)boot and recovery volumes for the version of macOS you are currently using.