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.
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> --compact
The 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.