Mount a Ubuntu Live CD and boot into it. Install zerofree
sudo apt-get install zerofree
If the package cannot be found, try enabling Multiverse repository (Software Sources).
Find out which drive you want to shrink
df
Run zerofree
sudo zerofree /dev/sda1
Once finished, shut down the Virtualbox machine and use Virtualbox to compact the hard disk image file
VBoxManage modifyvdi /path/to/the/image.vdi compact
Done.