Resize APFS Container

disk-utilitydiskutilhard drivepartitionssd

I've just been able to reassign the correct format to my SSD to APFS, see this question. however I notice that my Container isn't set to the proper size. I assume this is because the drive previously had a Bootcamp partition that I erased to install macOS Mojave, and now have completely erased. I have seen guides such as this one, but I wasn't comfortable trying any of these myself. The container in question is /dev/disk2s2 – Container disk4. The container is set to 439.9 GB instead of 500 GB. I know some of this space will go to the Preboot, Recovery, and VM partitions, but that still leaves a good 55 GB unaccounted for. Any help would be greatly appreciated.

Below is output from diskutil list.

Last login: Tue Oct  2 16:04:12 on ttys000
Trevors-MBP:~ trevorraney$ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_APFS Container disk1         499.9 GB   disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +499.9 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            488.3 GB   disk1s1
   2:                APFS Volume Preboot                 23.6 MB    disk1s2
   3:                APFS Volume Recovery                511.0 MB   disk1s3
   4:                APFS Volume VM                      4.4 GB     disk1s4

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:                 Apple_APFS Container disk4         439.9 GB   disk2s2

/dev/disk4 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +439.9 GB   disk4
                                 Physical Store disk2s2
   1:                APFS Volume Trevor                  412.6 GB   disk4s1
   2:                APFS Volume Preboot                 19.6 MB    disk4s2
   3:                APFS Volume Recovery                517.8 MB   disk4s3
   4:                APFS Volume VM                      4.3 GB     disk4s4

Trevors-MBP:~ trevorraney$ 

Here is the output from diskutil apfs list.

Trevors-MBP:~ trevorraney$ diskutil apfs list
APFS Containers (2 found)
|
+-- Container disk1 56EEF637-AE5B-448D-8E2D-54CE60A07231
|   ====================================================
|   APFS Container Reference:     disk1
|   Size (Capacity Ceiling):      499898105856 B (499.9 GB)
|   Capacity In Use By Volumes:   493466292224 B (493.5 GB) (98.7% used)
|   Capacity Not Allocated:       6431813632 B (6.4 GB) (1.3% free)
|   |
|   +-< Physical Store disk0s2 1764349E-6FCC-4237-B6E9-033B7AC6E066
|   |   -----------------------------------------------------------
|   |   APFS Physical Store Disk:   disk0s2
|   |   Size:                       499898105856 B (499.9 GB)
|   |
|   +-> Volume disk1s1 60CE9F60-BDC5-3AE2-9C0E-17E161EFC8E9
|   |   ---------------------------------------------------
|   |   APFS Volume Disk (Role):   disk1s1 (No specific role)
|   |   Name:                      Macintosh HD (Case-insensitive)
|   |   Mount Point:               /
|   |   Capacity Consumed:         488329256960 B (488.3 GB)
|   |   FileVault:                 No
|   |
|   +-> Volume disk1s2 93EFE3E1-2478-4D0F-977D-C3BB5BBB40BC
|   |   ---------------------------------------------------
|   |   APFS Volume Disk (Role):   disk1s2 (Preboot)
|   |   Name:                      Preboot (Case-insensitive)
|   |   Mount Point:               Not Mounted
|   |   Capacity Consumed:         23613440 B (23.6 MB)
|   |   FileVault:                 No
|   |
|   +-> Volume disk1s3 820C0712-37E3-44C1-809F-584D2ECAB349
|   |   ---------------------------------------------------
|   |   APFS Volume Disk (Role):   disk1s3 (Recovery)
|   |   Name:                      Recovery (Case-insensitive)
|   |   Mount Point:               Not Mounted
|   |   Capacity Consumed:         511004672 B (511.0 MB)
|   |   FileVault:                 No
|   |
|   +-> Volume disk1s4 DBE94C46-6345-4D74-97AA-386E2D3706F1
|       ---------------------------------------------------
|       APFS Volume Disk (Role):   disk1s4 (VM)
|       Name:                      VM (Case-insensitive)
|       Mount Point:               /private/var/vm
|       Capacity Consumed:         4440952832 B (4.4 GB)
|       FileVault:                 No
|
+-- Container disk4 15FA6D9A-A22C-450F-88B8-C1B82BC66B13
    ====================================================
    APFS Container Reference:     disk4
    Size (Capacity Ceiling):      439900680192 B (439.9 GB)
    Capacity In Use By Volumes:   417632681984 B (417.6 GB) (94.9% used)
    Capacity Not Allocated:       22267998208 B (22.3 GB) (5.1% free)
    |
    +-< Physical Store disk2s2 E934D562-60EA-42E2-BD30-55AE29CB24D9
    |   -----------------------------------------------------------
    |   APFS Physical Store Disk:   disk2s2
    |   Size:                       439900680192 B (439.9 GB)
    |
    +-> Volume disk4s1 96AB9124-CB87-3576-BF0A-3F4982945678
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk4s1 (No specific role)
    |   Name:                      Trevor (Case-insensitive)
    |   Mount Point:               Not Mounted
    |   Capacity Consumed:         412644388864 B (412.6 GB)
    |   FileVault:                 No
    |
    +-> Volume disk4s2 FA30E876-78CB-46AE-A537-A1F6EDB90D01
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk4s2 (Preboot)
    |   Name:                      Preboot (Case-insensitive)
    |   Mount Point:               Not Mounted
    |   Capacity Consumed:         19603456 B (19.6 MB)
    |   FileVault:                 No
    |
    +-> Volume disk4s3 8C227F5B-378E-4988-8F9E-CBD1EDF37617
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk4s3 (Recovery)
    |   Name:                      Recovery (Case-insensitive)
    |   Mount Point:               Not Mounted
    |   Capacity Consumed:         517754880 B (517.8 MB)
    |   FileVault:                 No
    |
    +-> Volume disk4s4 817A984A-3063-4680-A99B-26C6832241CE
        ---------------------------------------------------
        APFS Volume Disk (Role):   disk4s4 (VM)
        Name:                      VM (Case-insensitive)
        Mount Point:               Not Mounted
        Capacity Consumed:         4295049216 B (4.3 GB)
        FileVault:                 No
Trevors-MBP:~ trevorraney$ 

Best Answer

If you do have free space on your disk then Disk Utility.app should allow you to resize into it, but this is only possible if the free space exists after your APFS container, which I believe should be the case for an old Bootcamp volume.

In Disk Utility locate your physical disk (if you don't see it, press Command and 2 together to show all), select the physical disk and click the Partition button and you'll see a circular "pie chart" of your partitions starting from the top centre (12 o'clock) position and working their way around clockwise. One of these will be your APFS container and will show your APFS volumes stored within it, and after that you should see your free space (if any) as another "slice". Unfortunately I don't have a disk with any meaningful free space so I'm not 100% sure how Disk Utility will display this, it may appear as an "Untitled" partition that you can remove, or just as a blank segment.

To expand your container select it so that a little circular handle appears, drag this until it occupies all of the free space (alternatively you can enter the size in the box to the right). If you don't see the handle you may need to first select the empty space and "delete" it with the minus button. In this case Disk Utility should expand your container automatically, but you should double check it in case. Once you're happy with how the layout looks, click apply; you will receive a summary of the changes that are about to be made, double and triple check this to make sure your container will not be deleted, only resized.

Below is an image of how one of my disks looks in the partitioning UI:

Disk Utility UI Example

Here you can you see that I've resized my container (currently holding two volumes, macOS and Users) to take up some of the space of another partition (the cross-hatched section is the current size of the container, the flat blue section is new space that will be taken from "Untitled").

NOTE: Disk Utility can be a bit finicky about what it will let you do to a live APFS container/volume, so you might not be able to expand the container if one or more volumes are mounted. In this case you'll need to restart into recovery (Command and R after the startup chime) and run Disk Utility from there.

NOTES 2: I realise you may not need an answer anymore, but I thought I'd answer anyway for anyone finding this in searches etc. Hope you can get your disk woes resolved!