2008. december 17., szerda

Compacting a Virtualbox (Sun xVM) hard disk - freeing up space

I've just realized that my virtualbox install takes up 25 gigs, however, while checking out the filesystem in the VM, only 17gigs of space is used. It seems that virtualbox will not automatically free up this space, you have to do it manually, by issuing the following command:

 VBoxManage modifyvdi <name of the .vdi file> compact

Here is the output:

modifyvdi NewHardDisk1.vdi compact
VirtualBox Command Line Management Interface Version 2.0.6
(C) 2005-2008 Sun Microsystems, Inc.
All rights reserved.

Shrinking '/media/sdb1/innotek/NewHardDisk1.vdi': 0%...........10%..........20%..........30%..........40%..........

50%..........60%..........70%..........80%..........90%..........100%
 
That's it, however, don't expect too much size reduction (it only freed up 700MB on a 25G hard disk...)

PS: actually to make it work, I had to create a symlink to the .vdi file in ~/.VirtualBox/VDI/, maybe you'll need this, too.

Update: In order to get a greater file size reduction, you need to zero all the space on the hard disk (the compacting algorithm works by eliminating all parts of the hard disk image which contain zeros. Some advice on doing this can be found here.