I've got an Ubuntu 64bit VM that I derived from a ~1GB ova file, I used it under VMware vSphere to install some more software on it and use the system against a few datasets that took some 2-3GB of space, but now that I deleted these big files, I was expecting that the newly generated ova file from it would also take about ~1.1GB of space, but instead is taking about 3GB. If I look at the details the .vmdk file in virtualbox, I see the following:

Hart Disk: SATA Port 0
Type (Format): Normal (VMDK)
Virtual Size: 8.00 GB
Actual Size:  7.90 GB
Details: Dynamically allocated storage
Location: /somewhere/myVM-disk1.vmdk
Attached To: myVM.virtualbox

The size of the ova when I export this machine is ~3GB.

Any ideas how I can shrink it?

2 Answers 2


A space in .vmdk is allocated when OS makes a first write into particular sector. Once written, it's allocated forever.

So, you need to add second dynamically-sized virtual HDD to your virtual machine, then boot VM from LiveCD, create partitions with fdisk and copy all of the files (cp -R). Then shutdown VM, swap virtual HDDs, boot again and verify everything works, then detach original virtual HDD from VM and delete it as a file on disk of the host system.

Direct copying with dd in VM won't work, because it will write each sector into target .vmdk file, so it will expand to its full size instead of shrinking.


See the article How to shrink a dynamically-expanding guest virtualbox image.

It describes how to shrink the disk via :

  1. Zero out the free space, using zerofree for Ubuntu
  2. Shrink the VM using
    VBoxManage modifyhd my.vdi –compact
  • I tried it following instructions from the article and got down from 3.5GB to 3.0GB. I couldn't replicate the last command, since I am getting an *.ova file out of the export: VBoxManage modifyhd my.ova -compact complains Could not get the storage format of the medium
    – 719016
    Dec 5, 2012 at 13:01
  • There is no export in this method and no .ova file : You just run zerofree inside the VM, shut it down, then compact.
    – harrymc
    Dec 8, 2012 at 10:12
  • Got it. I only have *.vmdk files, so I first converted to vdi with VBoxManage clonehd --format VDI my-disk1.vmdk my-disk1.vdi then applied the compact command, but the vdi size didn't change at all.
    – 719016
    Dec 8, 2012 at 12:53
  • Some file must be left over at the end of the file. Remove the maximum possible of files, then follow this tutorial. Also this article as well as this thread may help.
    – harrymc
    Dec 8, 2012 at 18:58
  • Typo: "end of the file" => "end of the disk".
    – harrymc
    Dec 8, 2012 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .