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 onlysdeletethe 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.
While I tried this only for .vdi files, it should work the same way for .vdmk files. The point is that the –compact option sorts out all sectors that are filled with zeros.
Enjoy!