1

My VDI file keeps growing and I don't understand why. VirtualBox support have confirmed this is an Ubuntu Guest OS issue, not a host VB one. (BTW, is this question best answered here, or should I be asking at https://superuser.com ?)

I am running latest VirtualBox (5.1.18) under Windows 7 (Home Premium) 64-bit as Host. Ubuntu 16.04 (latest patches) 64-bit as Guest. VDI file is using dynamically allocate storage up to 100G.

When I used to run Ubuntu 14.04 all seemed reasonable. Recently I have been finding the VDI image keeps growing in size. It has grown from 7G to 14G. (This may not be much to some of you, but with an 8G memory stick for backup it's a problem for me!) I can boot Ubuntu to Unity desktop and then immediately exit, and the image can grow by 0.5G.

In Ubuntu the output from df -h shows:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        97G  7.7G   84G   9% /

So that is saying there is an extra 6G beyond Used which has been "lost" compared to Avail. du -h -x -s / confirms 7.6G used.

  1. What & where is the extra missing storage?
  2. Are there known problems here between VirtualBox and Ubuntu 16.04 (14.04 did not seem to have this problem)? I am seeing some posts on the net stating that 16.04 is using excessive desktop memory, though nothing amounting to 6G....
0

2 Answers 2

2

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.

3
  • The partition is 100G, you're saying ext4 helps itself to 6G for housekeeping? Good grief! I don't think that's right, because the whole image started out smaller than that.
    – JonBrave
    Apr 10, 2017 at 19:52
  • 1
    @JonBrave Because you are using dynamically allocate storage, everything is virtualized, you can do the same test as I did on my VM, I'm pretty sure you will get an answer close to your 6G.
    – Ravexina
    Apr 10, 2017 at 20:43
  • N.b. run sudo rm /home/zero when after rebooting else you'll have a full disk...
    – Lee
    Jan 12, 2018 at 15:06
0

Had the same problem Ubuntu 16.04 on Win7 VirtulBox 5.2.0:

The following steps solved it (thanks to Ravexina's answer above and this:

Guest Ubuntu:

sudo dd if=/dev/zero of=/home/zero bs=1M
shutdown

Host Win7 in cmd (change dir to location of .vdi):

C:/virtualbox/vboxmanage.exe modifymedium --compact MyPathTo/MyVM.vdi

Restarted guest Ubuntu:

sudo rm -rf /home/zero

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.