MacOS Compact VDI file

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:

  1. Login to the VM
  2. Run the following code:

sudo dd if=/dev/zero of=/tmp/nowt bs=4096k
sudo rm /tmp/nowt

  1. Shut down the VM
  2. Navigate to the folder containing the .vdi file
  3. Run this command:

VBoxManage modifymedium --compact [filename.vdi]