Resizing a virtual machine’s boot drive to use all available space
Every so often, it’s necessary to resize the boot drive of an existing virtual machine. The process of resizing the VM’s boot disk from outside the VM is usually pretty straightforward:
1. Shut down the VM
2. Go into the VM’s drive settings
3. Resize it to the desired size
4. Power on the VM.
However, when the VM boots up, the disk space used by the OS won’t have changed.
However, the OS can detect that there is available unallocated disk space that it isn’t using.
Fortunately, this is a correctable condition and the fix can be applied without needing to shut down the VM or boot from another drive. For more details, see below the jump.
The VM disk resizing process is a two-step process, where the first part is resizing the VM boot drive. The second step is resizing the drive partition using the OS’s tools to use some or all of the available unallocated space.
To tell the OS to use all of the available unallocated space, use the procedure described below:
1. Open Terminal
2. Run the command below:
diskutil resizeVolume / R
This command will tell macOS to do a live re-size of the boot partition, with the R flag specifying that all available unallocated space should be used.
3. The drive partition will resize to fill all available space.
4. The OS should now recognize and be able to use the now-allocated space.
I’ve written a script to run the appropriate diskutil command, which is available below and on my GitHub repo:
The script is below and is also available on my GitHub repo. 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.