Why Virtualbox VDI doubles the space of the VM hard disk?

0

I have one Xubuntu 12.10 64 bit Virtualbox VM on a Windows 7 64 bit host. It has one dynamic allocated hard disk with VDI format with maximum capacity of 20GB.

If I use a command df -h in the VM I get that 5.3GB are in use in th main partition. I have only 2 partitions, one for the ext4 hard disk and another with 512MB of swap. I have no snapshots.

The VDI file of this VM has 10.7GB. It is normal this difference of space? It is caused because the VDI format?

logoff

Posted 2012-11-07T15:58:10.983

Reputation: 197

Answers

1

You may have used 10,7GB in the past on the VM. The Dynamic VDI file can grow when you use more disk but it won't skrink when you use less. It will grow up to the size you defined for the VM (20GB). I don't know of any way (not saying there is not one) to shrink it other than making a new file and copying everything to it...

laurent

Posted 2012-11-07T15:58:10.983

Reputation: 4 166

maybe, but I do not remember using double space. – logoff – 2012-11-07T16:36:19.267

When you delete something the space is free for the VM but the file is not shrinked. When you write something new after that, the VM not always uses this freed space so it grows the file and keeps growing until it reaches the limit you configured as maximum. – laurent – 2012-11-07T16:40:58.730

you are right @laurent. this could be the reason, I have been using this VM during months. – logoff – 2012-11-07T16:45:08.927

1

You can shrink a VDI image

Roughly the steps are:

  1. Boot to safe mode (recovery mode) where you can access your root partition (/dev/sda1).
  2. Mount the root partition as read-only (mount -o ro /dev/sda1 /mnt/tmp)
  3. zero out the unused space with dd or zerofree
  4. Shutdown the virtual machine and run “VBoxManage modifyhd –compact /path/to/virtualboximage.vdi”

Martin Beckett

Posted 2012-11-07T15:58:10.983

Reputation: 6 073