# Resize disks in VirtualBox with Snapshots

virtualbox

It is quite straightforward to resize a disk in VirtualBox as stated here and there. It becomes tricky though if the virtual machine,aka VM, has snapshots attached. The virtual disk thus is persisted across multiple VHD files, and the old trick will generally take not effect. This is also a known bug hanging there for more than three years.

The suggested approach is to delete all snapshots and wait patiently for VirtualBox Manager to merge all the VHD files for you. It is a painfully lengthy process, so I decide to take a shortcut.

This method is provided AS IS with ABSOLUTELY NO WARRANTY, I will not be responsible for your data loss, and/or your house is burned. This method works for a dynamic allocated virtual disk with snapshots in VirtualBox 4.3.12, at least for me.

First, shutdown the VM and backup the whole virtual machine folder.

Then modify the size of all .vdi files in the root of the VM and Snapshots subdirectory.

VBoxManage modifyhd "Windows 8.1.vdi" --resize 81920
for x in Snapshots/*.vdi ; do VBoxManage modifyhd \$x --resize 81920 ; done

Startup the VM, and you will see the unallocated space in the Disk Management utility.

Update:

After this trick, I found that the Windows 8 VM takes about 160G disk while the Windows guest OS reports only 80G. I eventually full clone the original VM with only the latest state over night to claim the wasted 80G disk space.