Compress vdi file (virtualbox)

Number of Views : 24183

I mainly develop inside of a virtual server / application. In the last year I have been using Virtualbox instead of Virtual PC. I have a base image that I use as a testing machine. It is a base Windows XP image. I recently discovered that I could save some disk space by using a few commands to shrink / compact the vdi file.

To do this you will need to install a small application Nullfile ( This allows the empty disk space / unused data bytes to be filled with zero-bytes. You can read more about this at (

Once you have the file copy it to your Virtual Image. Run a disk defrag on your Virtual box system. After running a few defrags, you now need to just run the nullfile.exe. You only need to doubleclick the .exe.

Once the file is done, shut down your virtual image.
Open a command prompt and navigate to the directory where your vdi file is located. Mine is c:\vpc

Once in that directory we will be running the vboxmanage utility. On my Windows 7 pc it is located at C:\Program Files\Sun\VirtualBox\VBoxManage.exe

Here is the command we will be using modifyhd -compact

“C:\Program Files\Sun\VirtualBox\VBoxManage.exe” modifyhd -compact “c:\vpc\BaseXP.vdi”

Once this was completed my virtual image went from 4.3Gig to 2.7Gig.

Have fun with this utility. I was able to shrink my typical Windows 2008 server image to a much smaller size.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.