Home > Apple File System, Virtualization, VMware, VMware ESXi > Resizing a macOS VM’s APFS boot drive to use all available disk space

Resizing a macOS VM’s APFS boot drive to use all available disk space

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}'

Screen Shot 2017 10 18 at 4 42 53 PM

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

Screen Shot 2017 10 18 at 5 05 59 PM

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.

Screen Shot 2017 10 18 at 4 46 55 PM

Screen Shot 2017 10 18 at 4 47 01 PM

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

Screen Shot 2017 10 18 at 4 44 44 PM

Once the container resizing has completed, the OS should now recognize and be able to use the newly-allocated space.

Screen Shot 2017 10 18 at 4 45 32 PM

Screen Shot 2017 10 18 at 4 45 11 PM

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.

  1. October 30, 2017 at 8:06 pm

    when I do this command
    diskutil apfs resizeContainer disk0 0
    I get this error
    Error: -69771: The target disk is too small for this operation

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: