Compacting Virtual Box Drives

Too many times I’ve forgotten the exact commands on how to compact the virtual drives. Especially for windows, where the tool used, used to have a different name of the argument passed to it. Compacting the drive can save you lots of disc space (last time my drive went from 12GB to 5GB), and for a smaller lap top drive, that makes a big difference.

Windows Guest: Download SDelete from SysInternals and then run

1
SDelete.exe z

Linux Guest: Here, we create a file that fills the entire empty space, and then deleting it:

1
dd if=/dev/zero of=fillfile bs=1M rm fillfile

Host: Finally, you let VirtualBox compact the drive

1
VBoxManage modifyhd harddrivename.vdi --compact

That’s it really! I hope I’ll remember it a little better this time.

Further info:


Mathias Westerdahl

Mathias Westerdahl

A game developer since 2001. Currently at http://www.defold.com. Find me at twitter