Every now and then, a project I'm managing through Vagrant (using either a box I built myself using Packer, or one of the many freely available Vagrant Boxes) needs more than the 8-12 GB that's configured for the disk image by default. Often, you can find ways around increasing the disk image size (like proxying file storage, mounting a shared folder, etc.), but sometimes it's just easier to expand the disk image.
Unfortunately, VBoxManage's modifyvm --resize
option doesn't work with .vmdk disk images (the default format used with Vagrant boxes in VirtualBox). Luckily, you can easily clone the image to a .vdi image (which can be resized), then either use that image, or convert it back to a .vmdk image. Either way, you can expand your virtual disk image however large you want (up to the available free space on your physical drive, of course!).
Here's how:
1 - Convert and resize the disk image
First, vagrant halt
/shutdown your VM, then in Terminal or on the command line:
# Clone the .vmdk image to a .vdi.
vboxmanage clonehd "virtualdisk.vmdk" "new-virtualdisk.vdi" --format vdi
# Resize the new .vdi image (30720 == 30 GB).
vboxmanage modifyhd "new-virtualdisk.vdi" --resize 30720
# Optional; switch back to a .vmdk.
VBoxManage clonehd "cloned.vdi" "resized.vmdk" --format vmdk
The third step is not absolutely required—you could update your VM in VirtualBox or via the command line to use the .vdi, and then discard your original .vmdk—but it's simple enough to switch back to a .vmdk, and doesn't require any further configuration changes.
2 - Resize the disk image using gparted
- Download the gparted .iso
- Mount the .iso as a CD/DVD drive in VirtualBox for your VM
- Start your VM, and on the boot screen, hit F12 to select the gparted iso image for boot
- Follow the instructions for gparted's startup, then in the GUI (or on the command line) resize the partition on your new disk image so it uses all the unallocated free space).
Now shut down the VM again, unmount the gparted ISO, and reboot with your newly-expanded disk image.
Thanks to this SO post and this post for the details.
Comments
I'm using a Mac and following your instructions. I've managed to clone the vmdk to a vdi (eventually) but when I then try to increase its size I'm getting the following error message: 'VBoxManage: error: Resize hard disk operation for this format is not implemented yet!'
Any ideas?
You are trying to resize the wrong hd. Resize the .VDI hd
Thanks so much for this! Worked perfectly on a Mac to resize a Windows 7 vmdk.
Thanks! This worked perfectly. As you suggested I kept the image as vdi (I did not convert it back to vmdk) and just changed it in my VM configuration.
Many tks!! Worked perfectly!!
My case also, it is like - I am able clone vmdk to vdi and then able to increase vdi but not able to convert the vdi back to vmdk
I was able to clone my vmdk to a vdi, but when I try to resize it, it just instantly spits out the progress output and the image stays the same size. Any idea why it would do that? I've removed the snapshots it had, flattening it. Thanks!
# vboxmanage modifyhd "windoze 10-disk1.vdi" --resize 81920
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Hi! I just submitted a comment about how resizing my vdi didn't work. Please disregard- it DID actually work. I assumed it didn't because it went too fast and the file size was the same. But when I booted into windows, it showed 80G! Thanks!
Glad it helped!
To switch to using the VDI in the interface click on storage. And then you can remove the .vmdk, and add the .VDI.
The other thing is the resize is very fast.
Thanks, your instructions worked easily with no problems - nobody else's did. Very much appreciated!!!
Hi,
Cloning to .vdi from .vdmk worked fine. However after I resize the .vdi (goes very quick) and start the Windows VM using the .vdi, the disk size is the same as before. File size also same as it was before. Am I missing something? Tried a few times with same results (no errors) Using latest VBox on Mac with Sierra IOS.
TIA for any clues you might provide.
Windows partition resizing works a little differently than on Linux, I think, so you’ll have to find out how to expand the partition within windows.
This guide was incredibly helpful.
I successfully expanded a VMDK file of a Windows 8.1 guest on a macOS El Capitan host (MacBook Pro (Retina, 15-inch, Mid 2015)).
Thank you, Mr. Geerling!
Please remember that you need to manage the hard disk and extend the partition to the new size
AWESOME guide! Easy to follow and super useful! Thank you!
Thanks! Works great.