Virtual disk images (.vdi files) tend to grow over time, especially with windows guest systems, and may quickly consume all your disk space on the host system.
This post shows the required steps to free up the unused space. It worked for me with Sun/Oracle VirtualBox versions of 3.1.6 and above.
For a Windows guest system
- Start a Defragmentation (right-click disk icon, select properties->Tools tab-> Defragment now…)
- Download SDelete (about 47kb) into your guest.
Wait for the defragmentation to complete.
- Fill the free space of your vdi disk image with zeros executing
(with SDelete 1.5
) sdelete -cor
(with SDelete 1.6
) sdelete -z
from a DOS command line. (Check your version by entering only
sdeletethe option which is ‘good for virtual disk optimization’ is the right one)
This step may take a lot of time (20min for a 20GB disk on my system). Don’t use the guest system during the process.
- Shut down your windows guest system.
- Make a backup of your .vdi file.
- On your HOST system, execute the following command in a DOS/terminal window:
VBoxManage modifyhd <diskname.vdi> --compactThe VBoxManage tool is part of the VirtualBox standard distribution.
Whis works only for .vdi files. If you want to shrink a .vdmk file, use the
VBoxManage clonehd <in.vdmk> <out.vdi> --format VDI command.