VirtualBox VDI file size keeps growing with Ubuntu 16.04

In my knowledge, when you or any program writes something to the disk, after removing that file only the related inode to that file will be removed and data (zero and ones) remains on the disk, so while you are using dynamic allocated storage, the VirtualBox has no idea what files are living in your OS, it's just know for example 10G of data has been written to your disk, so it growth your hard disk size to manage that 10G of data.

What you can do?

  1. zero out the free space of hard disk in guest, in Linux distributions you can use dd utility to do that:

      sudo dd if=/dev/zero of=/home/zero bs=1M
    
  2. then use VBoxManage command with --compact switch to make your VDI files compact.

    VBoxManage modifyhd '/home/ravexina/VirtualBox VMs/Ubuntu/ubuntu.vdi'
    

More infromation about compacting: here

Reserved blocks

And about the size you mentioned, I guess that would be the reserved blocks for ext4 file system. for my home partition which is sda2.

user@machine:~$ sudo tune2fs -l /dev/sda2 | grep -ie 'reserved block count'

Reserved block count: 1408704 

And because my block size is 4096 byte, so 1408704x4096 makes 5770051584 bye which equals to 5.77 GB reserved space on my home patition.