In the Linux Guest system:
dd if=/dev/zero of=/var/tmp/bigemptyfile bs=4096k ; rm /var/tmp/bigemptyfile
Note that dd will use up all the free space
Or
telinit 1
mount -o remount,ro /dev/sda1
zerofree -v /dev/sda1
Edit fstab to have the mount point in question mounted read-only by default
vi /etc/fstab
Make the appropriate entry ‘ro’
/dev/sda1 / ext4 ro 0 1
Reboot and run zerofree -v /dev/sda1
now
mount -o remount,rw /dev/sda1
/etc/fstab
again to restore the original contentshutdown -h now
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd --compact "c:\path\to\linux-disk-image.vdi"