Seriously, How to Compact a vdi?

In my home shop, a lot of testing gets done using Virtualbox. As part of that testing backups are commonly made of virtual machines that mirror production configurations. I typically use thin provisioning on my test rigs. On of the things i have noticed is in working with the virtual machines the backups get very large over time. One way to stave off this problem is prior to running your backup, whether it be export to .ova or just copying the .vdi, I run the following command in my linux guest.

dd if=/dev/zero of=EMPTY bs=1M rm -f EMPTY

What this essentrially does is zero out all of the free space on the VM guest hard drive. Once that is complete, shut down the VM and then run the following command on the Virtualbox host.

VBoxManage modifyhd [your.vdi] compact

this will recapture the free space that has been taken by the guest hard drive. Once the command is complete you can backup your guest VM and you will notice that the backup size should be much smaller.

Did you find this article useful? Why not share it with your friends?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.