Shrinking a bloated VirtualBox disk image

Sunday, October 9th, 2011 | Misc, Tech-savvy

I like to keep my house clean. I was always puzzled by ever growing vdis (VirtualBox disk images). Just today I did a clean install of WinXP Home SP1 and installed SP3 afterwards (a pity the online photo printing software my wife uses is only available for Windoze). After getting rid of everything that bloated my VM in the first place I was still sitting on a 2.6 Gig image. Seemed a tiny bit too much, so I looked for a way to make sure the vdi only holds real data, not “empty” space.

The trick I am about to show you made me decrease the real size of my vdi from 2.6 to 1.5 Gig. That’s pretty neat and you should be able to free up even more space if you already used your VM quite heavily (more fragmented thus more space available to optimize).

It’s simple: first defrag your virtual host’s file system, second make sure the empty space is really empty (I used nullfile 1.2). After that, use VirtualBox‘s command line tool VBoxManage to recompress the image:

VirtualBox 3.x:

VBoxManage modifyvdi WinXP.vdi compact

VirtualBox 4.x:

VBoxManage modifyhd --compact WinXP.vdi

That’s it. This trick may be rather old, yet helped me save some bytes. Not that I actually needed that extra Gig, but hey, why should I waste it? 🙂


No comments yet.

Leave a comment