A while back, I wrote a post on how to resize the boot drive of an existing virtual machine. However, that guidance only applies to a boot drive that uses HFS+ for its filesystem.
Now that Apple File System (APFS) is available and the default file system on macOS High Sierra, a different procedure must be used in order to resize the APFS-formatted boot drive of an existing virtual machine. For more details, see below the jump.
For an APFS boot drive, 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 boot volume, use the diskutil command shown below:
/usr/sbin/diskutil info / | awk '/Part of Whole/ {print $4}'
2. Once the appropriate APFS container has been identified, use the diskutil command shown below to resize the container with all available disk space.
Note: You can specify a size of zero (0) to grow the targeted container using all unallocated drive space.
/usr/sbin/diskutil apfs resizeContainer /dev/apfs_container_id_goes_here 0
In this example, I have a VM where my APFS-formatted boot drive is using 42.7 GBs of space, but the VM disk has 85.9 GBs of available space.
Assuming that the command above gave us disk1 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 /dev/disk1 0
Once the container resizing has completed, the OS should now recognize and be able to use the newly-allocated space.
I’ve updated an existing script to identify if a boot drive is running HFS+ or APFS, then run the appropriate diskutil commands for that filesystem. It is available below and on my GitHub repo:
https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/resize_vm_boot_partition
This script is also available as a payload-free package on my GitHub repo, available for download from the payload_free_package directory available from the link above.