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

  2. Steve
    February 18, 2018 at 6:23 pm

    Hello, i got in High Sierra Error: -69743: The new size must be different than the existing size

    diskutil list
    /dev/disk0 (internal, physical):
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *240.1 GB disk0
    1: EFI EFI 209.7 MB disk0s1
    2: Apple_APFS Container disk1 119.8 GB disk0s2

    /dev/disk1 (synthesized):
    #: TYPE NAME SIZE IDENTIFIER
    0: APFS Container Scheme – +119.8 GB disk1
    Physical Store disk0s2
    1: APFS Volume Mac 116.1 GB disk1s1
    2: APFS Volume Preboot 19.4 MB disk1s2
    3: APFS Volume Recovery 509.8 MB disk1s3
    4: APFS Volume VM 2.7 GB disk1s4

    Any ideas?

  3. February 22, 2018 at 3:45 pm

    Reblogged this on [+] Blog del Chote [+].

  4. September 22, 2018 at 10:11 pm

    Dedicated vm os x image on a 250GB 550ms SSD

    HFS and VMware – while booting:
    command+s
    At single mode prompt: fsck -fy
    Repeat until there’s no more errors
    At prompt: reboot
    From terminal as root execute:
    /usr/sbin/diskutil resizeVolume / R
    Done

    HFS and Parallels – Do before booting
    In VMConfiguration-> Hardware -> Boot Order > Advance enter the following
    devices.mac.boot_args=”-s”
    Then boot image
    At single mode prompt: fsck -fy
    Repeat until there’s no more errors
    At prompt: shutdown -h now
    In VMConfiguration-> Hardware -> Boot Order > Advance remove the entry
    devices.mac.boot_args=”-s”
    Boot into vm image
    From terminal as root execute:
    /usr/sbin/diskutil resizeVolume / R
    Done

  5. November 9, 2018 at 12:43 am

    Tried to do the above, but it failed.

    Turned out I had an Apple_KernelCoreDump partition in the way:

    diskutil list
    /dev/disk0 (internal, physical):
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *64.4 GB disk0
    1: EFI EFI 209.7 MB disk0s1
    2: Apple_APFS Container disk1 49.6 GB disk0s2
    3: Apple_KernelCoreDump 655.4 MB disk0s3

    /dev/disk1 (synthesized):
    #: TYPE NAME SIZE IDENTIFIER
    0: APFS Container Scheme – +49.6 GB disk1
    Physical Store disk0s2
    1: APFS Volume Macintosh HD 43.0 GB disk1s1
    2: APFS Volume Preboot 44.2 MB disk1s2
    3: APFS Volume Recovery 516.7 MB disk1s3
    4: APFS Volume VM 1.1 GB disk1s4

    Was able to:
    sudo diskutil erasevolume “Free Space” %noformat% /dev/disk0s3
    sudo diskutil apfs resizeContainer disk0s2 0

    to get there. I assume disk1 would have worked, too.

  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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: