Resizing a VirtualBox Disk Image (.vmdk) on a Mac
This post is more than 10 years old. I do not delete posts, because even old information is still useful, but please know that some material on this page may be outdated or incorrect. Thanks!
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