— Tech, Virtual machine, Tool, Tip — 1 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.
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:
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.
Shut down the guest.
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>