Virtualbox VDI disk grow when you use it. I have many virtual machines and sometimes optimizing VDI free space can recover some precious gigabytes… I have some Virtual Machines that I usually don’t use, but I like to have on disk when something bad happens, so a small VDI is a nice thing.

Usually I’m using as main OS Linux or OSX so I need to virtualize Windows.

To optimize the VDI, you have to:

  1. start the Virtual Machine and erase anything you don’t use. I suggest some freeware like CCleaner to deep clean the Virtual Machine (the browser’s cache, temporary files, etc…)
  2. get the SDelete utility and run it from terminal to clean the free space (also CCleaner can clean the free space, but SDelete is faster)
    sdelete -z c:
  3. power off the Virtual Machine and open a terminal where the VDI is located. Run the command VBoxManage to optimize the VDI disk (replace “THE NAME OF VDI HERE” with your VDI name 🙂 ). Try to use the full VDI path, to avoid errors.
    VBoxManage modifymedium "/FULL/PATH/OF/VDI/THE NAME OF VDI HERE.vdi" --compact
  4. (optional) if you get the error “VBoxManage: error: Cannot register the hard disk ‘/FULL/PATH/OF/VDI/THE NAME OF VDI HERE.vdi’ {ee23e92f-4a72-xxxx-bfc7-075de81084d5} because a hard disk ‘/FULL/PATH/OF/VDI/THE NAME OF VDI HERE.vdi’ with UUID {ee23e92f-4a72-xxxx-bfc7-075de81084d5} already exists”, you can change the UUID with this command (it’s a quick and easy solution, no need to clone the entire disk to change the UUID)
    VBoxManage internalcommands sethduuid "/FULL/PATH/OF/VDI/THE NAME OF VDI HERE.vdi"

With this technique you can recover free disk space (with small SSD it’s a great plus). The commands used into this post are from OSX, but with Linux/Windows as host they are very similar if not identical.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *