In order to compact a virtualbox VDI file and recover some of the lost space (especially useful when using a VM for your development databases) then its really rather simple:
- Login to the VM
- Run the following code:
sudo dd if=/dev/zero of=/tmp/nowt bs=4096k
sudo rm /tmp/nowt
- Shut down the VM
- Navigate to the folder containing the .vdi file
- Run this command:
VBoxManage modifymedium --compact [filename.vdi]