· 4 Min read

Compacting a VirtualBox VDI

Post

Virtualbox is now one of the most indispensable tools in any programmer’s arsenal these days, providing endless virtual machines for testing, analysis, debugging and sandboxing of applications, operating systems, viruses, etc. But like any VM, you’ll run into what I like to call ‘virtual bloat’; vm disk sizes balloon in size in physical space when in actuality, they take up much less (~1/3 size reduction is typical). Here’s what I do to get it back down to size:

  1. Defragment the system (I like to use JK Defrag GUI)
  2. Zero out the free space (use ‘sdelete.exe -c‘ to clear up space)
  3. Run ‘VBoxManage modifyvdi <vdi file location> compact’ from the command prompt

That’s it. Using this method, I reclaimed 14GB from an actual 3GB of vm disk usage!

With a future revision, they’ll make this entire process automated (similar to vmware). Not sure when, but it’s bound to happen.