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:
https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/resize_vm_boot_partition
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Resize boot volume to occupy all available space on the partition | |
/usr/sbin/diskutil resizeVolume / R |
Thanks Richard, I was looking to do exactly this the other day. This should save me from having to completely recreate my VM next time
Hi Rich, from my experience, Disk Utility under Sierra is now able to show the added space on the virtual harddrive as “Free” (iirc), which was not the case under El Capitan. In the gui, you can now add the space to a volume without the need of the cli.