Skip to content
Maxwell Abrams

Free Phyiscal Disk Space By Compacting VirtualBoxs VDI

Tech, Virtual machine, Tool, Tip1 min read

I run many servers using VirtualBox. To give myself flexibility, I often use a dynamically sized VDI. This works well because I can let my services use space as required without needing scale my storage.

virtual box UI

However, this can be a problem when guest frees memory on the virtual disk. When files are deleted, they aren't actually zeroed-out. Instead, the references to those files are removed but the bits are still occupied. This isn't a problem with a single OS, but in the virtualized world this causes the host's disk to still use space.

Here are some steps to zero out the virtual disk so that the host can free the physical disk space:

  1. On the guest run:

Linux/Mac: dd if=/dev/zero of=/var/tmp/zero_file bs=4096k ; rm /var/tmp/zero_file

Windows: Run defrag or Google for any zero-ing tool. It is possible the new Linux Subsystem can help with this.

  1. Shut down the guest.

  2. On the Host, run:

Mac: VBoxManage modifymedium --compact </path/to/the_disk.vdi>

Linux: vboxmanage modifymedium --compact </path/to/the_disk.vdi>

Windows: VBoxManage.exe modifymedium --compact <C:\path\to\the_disk.vdi>

  1. Check your physical disk space! The VDI should be nice and compact now.

status

© 2024 by Maxwell Abrams. All rights reserved.
Disclaimer