How to Resize a VirtualBox VDI or VHD File on Mac OS X
If you use VirtualBox to run guest operating systems within a virtual machine on the Mac, like Windows 10 or Ubuntu Linux, you may find yourself needing to resize the virtual disk size where the OS resides. This is often the case when you inadequately estimate how much space is required for properly installing in a virtual machine with dynamically allocated storage.
To resize a VDI or VHD file in OS X (this may work the same in linux, let us know), you’ll use the VBoxManage tool from the Mac command line. Even if you chose to install the VirtualBox command line tools, it won’t be in your path, so you’ll be heading into the VirtualBox.app contents to use the utility instead.
Since this is modifying the virtual machine, it’s a good idea to back up the VDI or VHD file beforehand, if you’re not comfortable with the terminal at all you should probably back up the entire Mac first. Keep in mind the resize utility uses megabytes for measurement, so if you’re changing a vm file to be 30GB that would be 30000MB, 50GB as 50000, and so forth.
- Shutdown the VM and quit VirtualBox
- Open the Terminal app and use the following command to navigate to the VirtualBox app directory:
- Now in the proper directory, you’re ready to run the resize command with the following syntax:
- If desired, verify the change has taken place with the showhdinfo command:
- Relaunch VirtualBox and boot your newly resized guest OS
VBoxManage modifyhd --resize [new size in MB] [/path/to/vdi]
For example, let’s say there’s a Windows 10 VM VDI file located at /Users/Paul/Documents/VM/Windows10.vdi and we want it to grow from 15GB to 30GB, the syntax would be:
VBoxManage modifyhd --resize 30000 ~/Documents/VM/Windows10.vdi
VBoxManage showhdinfo ~/path/to/vmdrive.vdi
If the path to the VM file is in a deeply rooted or complex location, use quotes or using the drag drop to print path trick which works great in Terminal app to properly point to a complex directory hierarchy.
Resizing the drive with VBoxManage is basically instantaneous from the command line, but keep in mind that once you’re back in the virtual OS (Windows, OS X, Linux, or whatever else you have running in VirtualBox) you will probably want to reallocate the partition to use the new space.
I ran this to grow a dynamical allocation minimum size, if the VDI file is a fixed size and you want to shrink it, the VBoxManage tool will still do the job but the –compact flag is what you’re looking for.
VBoxManage is a helpful tool with a lot of great uses, you can also use it to quickly clone a virtual disk and modify nearly anything within VirtualBox from the command line. If you plan on using VBoxManage often, you may want to add it to your path or create an alias for easier access.
Know of another way to resize a VirtualBox VDI? Let us know in the comments.