First of all download SystemRescueCd, which we will use later to manipulate our virtual disk.

Download SystemRescueCd for free. A Linux system rescue disk as a bootable CD-ROM or USB stick. SystemRescueCd is a Linux system rescue disk available as a bootable CD-ROM or USB stick for administrating or repairing your system and data after a crash. It aims to provide an easy way to carry out adm…

Mount it to VM with VirtualBox GUI. Upon launching the VM it should automatically boot to SystemRescueCd. Choose the default option to go to the recovery system.

Next run fdisk -l to see the disk partitions. To me it's /dev/sda5. Then run

zerofree -v /dev/sda5

to start filling the empty space with zerofree. It should not take too much time, 1 or 2 minutes should do it. Then finally shutdown the system by shutdown now.

On your host, go to the .vdi location and run

VBoxManage modifyhd vm-disk001.vdi compact

Give it some time and the image should be shrinked.