I’ve started working with Amazon Web Service’s new macOS EC2 instances and after a while, I noticed that no matter how much EBS drive space I assigned to a EC2 instance running macOS, the instance would only have around 30 GBs of usable space. In this example, I had assigned around 200 GBs of EBS storage, but the APFS container was only using around 30 GBs of the available space.
After talking with AWS Support, there’s a fix for this using APFS container resizing. This is a topic I’ve discussed previously in the context of resizing boot drives for virtual machines. For more details, see below the jump.
To resize a macOS EC2 instance’s boot volume, you need to do two things:
1. Identify the appropriate APFS container:
APFS containers act as storage pools for APFS volumes. APFS volumes are what act as the mounted filesystem, where you store your files, directories, metadata, etc. When you grow the APFS container, the APFS volumes will likewise get additional space.
To identify the container for the instance’s boot volume, use the command shown below:
/usr/sbin/diskutil list physical external | awk '/Apple_APFS/ {print $7}'
2. Once the appropriate APFS container has been identified, use diskutil to resize the container with all available disk space.
You can specify a size of zero (0) to grow the targeted container using all unallocated drive space.
/usr/sbin/diskutil apfs resizeContainer apfs_container_id_goes_here 0
In this example, I have an instance where my APFS-formatted boot drive is using 32 GBs of space, but the instance has 200 GBs of available EBS disk space.
Assuming that the command above gave us disk1s2 as a result, the command shown below can be used to resize the boot drive’s APFS container with all available disk space.
/usr/sbin/diskutil apfs resizeContainer disk1s2 0
ec2-user@ip-172-31-23-238 ~ % /usr/sbin/diskutil apfs resizeContainer disk1s2 0 | |
Started APFS operation | |
Aligning grow delta to 182,536,110,080 bytes and targeting a new physical store size of 214,538,608,640 bytes | |
Determined the maximum size for the targeted physical store of this APFS Container to be 214,537,580,544 bytes | |
Resizing APFS Container designated by APFS Container Reference disk2 | |
The specific APFS Physical Store being resized is disk1s2 | |
Verifying storage system | |
Using live mode | |
Performing fsck_apfs -n -x -l -S /dev/disk1s2 | |
Checking the container superblock | |
Checking the EFI jumpstart record | |
Checking the space manager | |
Checking the space manager free queue trees | |
Checking the object map | |
Checking volume | |
Checking the APFS volume superblock | |
The volume Macintosh HD – Data was formatted by newfs_apfs (1412.141.1) and last modified by apfs_kext (1412.141.1) | |
Checking the object map | |
Checking the snapshot metadata tree | |
Checking the snapshot metadata | |
Checking the extent ref tree | |
Checking the fsroot tree | |
Checking volume | |
Checking the APFS volume superblock | |
The volume Preboot was formatted by diskmanagementd (1412.141.1) and last modified by apfs_kext (1412.141.1) | |
Checking the object map | |
Checking the snapshot metadata tree | |
Checking the snapshot metadata | |
Checking the extent ref tree | |
Checking the fsroot tree | |
Checking volume | |
Checking the APFS volume superblock | |
The volume Recovery was formatted by diskmanagementd (1412.141.1) and last modified by apfs_kext (1412.141.1) | |
Checking the object map | |
Checking the snapshot metadata tree | |
Checking the snapshot metadata | |
Checking the extent ref tree | |
Checking the fsroot tree | |
Checking volume | |
Checking the APFS volume superblock | |
The volume VM was formatted by diskmanagementd (1412.141.1) and last modified by | |
Checking the object map | |
Checking the snapshot metadata tree | |
Checking the snapshot metadata | |
Checking the extent ref tree | |
Checking the fsroot tree | |
Checking volume | |
Checking the APFS volume superblock | |
The volume Macintosh HD was formatted by diskmanagementd (1412.141.1) and last modified by apfs_kext (1412.141.1) | |
Checking the object map | |
Checking the snapshot metadata tree | |
Checking the snapshot metadata | |
Checking the extent ref tree | |
Checking the fsroot tree | |
Verifying allocated space | |
The volume /dev/disk1s2 appears to be OK | |
Storage system check exit code is 0 | |
Growing APFS Physical Store disk1s2 from 32,002,498,560 to 214,538,608,640 bytes | |
Modifying partition map | |
Growing APFS data structures | |
Finished APFS operation | |
ec2-user@ip-172-31-23-238 ~ % |
Once the container resizing has completed, the OS should now recognize and be able to use the now-allocated space.
This can be confirmed by other disk space measuring tools.
ec2-user@ip-172-31-23-238 ~ % df -h | |
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on | |
/dev/disk2s5 200Gi 10Gi 181Gi 6% 488252 2094615348 0% / | |
devfs 186Ki 186Ki 0Bi 100% 642 0 100% /dev | |
/dev/disk2s1 200Gi 5.7Gi 181Gi 4% 161309 2094942291 0% /System/Volumes/Data | |
/dev/disk2s4 200Gi 2.0Gi 181Gi 2% 1 2095103599 0% /private/var/vm | |
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /System/Volumes/Data/home | |
ec2-user@ip-172-31-23-238 ~ % |