yum install e2fsprogs-devel -y
wget http://frippery.org/uml/zerofree-1.0.3.tgz
tar -zxf zerofree-1.0.3.tgz
cd zerofree-1.0.3
make
after successfully building the application, copy it to /usr/bin
cp zerofree /usr/bin
Now you can remount the destination partition as read-only and zerofree it!
You can also use dd instead of zerofree:
dd if=/dev/zero of=test.file
...wait for the virtual disk to fill, then
rm test.file
and shut the VM down. Then on your VirtualBox host do:
VBoxManage modifyhd --compact yourImage.vdi