VirtualBox – Shrink your VDI images. Image size = Space used up inside VM.

Often when you install a VM in virtualbox you’ll notice that initial size of the VM image would be more or less equal to the disk space actually used in the VM. However with time, as you play around, you will find that the size of VM image would always keep on increasing. The disk space actually used would be far lesser than the VM image size. We would try to compress the VM image to the space actually used up inside the VM.

Pre-condition – The image that we are going to shrink should have been dynamically expanding type, when you created the disk very first time. This is explained for a windows VM. Theoretically should work on other VMs also.

Ok, Lets get started.

We’ll need the following tools:
1. : This tool zeroes out free space, which our next tool compresses. For Linux based OS, search for a file, zerospace.c, which you’ll have to compile yourself.

2. VBoxManage : This tool is the command line management tool that ships with VirtualBox. Whatever you can do with the GUI, can be done by this. + A lot more 🙂

Ok now.

1. First boot into your VM. Defragment your drive atleast 2 times.
2. Copy the tool, nullfile mentioned above to the VM and run it. A simple double click should do it.

Nullfile tool running in the VM

3. Now shutdown the guest. Open a terminal in the VM image directory. Most probably /home/_user_name_/.VirtualBox/VDI

2. Run our final command, We would be done after this.
VBoxManage modifyvdi _file_path_ compact

e.g. in my case I ran: VBoxManage modifyvdi /media/Blockk/VDI/NewHardDisk1.vdi compact

That’s it, It will take some time, and you’ll get your tiny, shiny, compressed VM image.

Using above tricks, I was able to compress my VM from 1.8gb to 700mb


44 Responses to “VirtualBox – Shrink your VDI images. Image size = Space used up inside VM.”

  1. Andrew Says:

    FYI, this method no longer works in VirtualBox 2.1.2 (possibly 2.1.0 also), because of changes to VBoxManage. It did work in 2.0.6.

  2. Конвертируем VMware образ в VirtualBox | Журнал веб разработчика Says:

    […] Ссылки по теме: • How To Convert From a VMware Image To Virtualbox Image • VMware to VirtualBox • Clone VirtualBox disk image on MS Windows mini-HOWTO • QEMU on Windows • Скачать • Switching From VMWare To VirtualBox: .vmdk To .vdi Using Qemu + VdiTool • VBoxTool • VirtualBox – setup, share, shrink, convert • VirtualBox – Shrink your VDI images. Image size = Space used up inside VM […]

  3. John Bäckstrand Says:

    Here is some related discussion with a few work-arounds:

  4. Andy Says:

    Apparently, using the clonehd command will shrink your vdi when it copies it, so that should be the simplest workaround out there.

  5. Adam Says:

    In your screenshot on the right hand side you have something monitoring your system and putting it on the desktop. What program is it and have you made any changes to the config file? If so, can you post that as well?


  6. Majed Sahli Says:

    For Windows Guests.. You can download SDelete utility from Microsoft to zero unused space with the option -c from here:

    Then you can use the following command from the Host OS..

    VBoxManage modifyhd –compact

  7. Andrea Says:

    It worked wonderfully for me!!!

    HOST: Ubuntu 8.04
    GUEST: Windows Xp
    VirtualBox: 3.04 r50677

    I was annoyed by my virtual OS taking 24GB (the maximum space of my dynamic expanding storage disk ) when the real OS disk usage was about 8GB…

    Now it is 8GB again… amazing.

    I hope it won’t grow again otherwise I will run the procedure once in a while.

    Thank you very much,

  8. Orlando Says:

    I got problems running nullfile 1.02.exe

    at some stage the process stop and this message appears

    Runtime error 101 at…..

    and nothing happens…. thae dummy file is not erased.

    Any comments?

  9. Flattening the learning curve » Blog Archive » mounting VirtualBox shared folders - Windows guest Says:

    […] This will define the drive X as the shared foldernet use x: \vboxsvr<folder> where <folder> has been defined using the virtual box  guess additionswhile on the subject of VirtualBox  – this shows how to shrink the vdi […]

  10. techspalace Says:

    and which version of vbox are we talking about ?

    -Regards, (not only Ubuntu blog)

  11. Xимeнa Says:

    Ну вы бы подрались еще, нашли о чем поспорить 🙂

  12. » Blog Archive » links for 2010-03-03 Says:

    […] VirtualBox – Shrink your VDI images. Image size = Space used up inside VM. « Ubuntu, Life, Mobile… (tags: compression virtualbox shrink vdi) […]

  13. » Blog Archive » links for 2010-03-04 Says:

    […] VirtualBox – Shrink your VDI images. Image size = Space used up inside VM. « Ubuntu, Life, Mobile… (tags: compression virtualbox shrink vdi) […]

  14. » Blog Archive » links for 2010-03-11 Says:

    […] VirtualBox – Shrink your VDI images. Image size = Space used up inside VM. « Ubuntu, Life, Mobile… (tags: compression virtualbox shrink vdi) […]

  15. broomiLooft Says:

    Как улучшить зрение и какие методы использовать? [url=]Глазные капли Эй-пи-ви с прополисом, фирмы Тентори…

  16. Jason Says:

    Download a random EXE from an unknown site and run it on my Windows box? Are you out of your mind? No way. That’s the way to virus city.

  17. nerkn Says:

    If you have data dont expect to shink more than that. I have 2.7G data and my file is like same. It didnt shrink

  18. Anonymous Says:

    7zip advantages?

  19. VirtualBox – Ubuntu, disk image fun « Winlindocs's Blog Says:

    […] ~2.95GB was about the size this particular image ended as, you can also use this tool to further compress images (700MB!) […]

  20. MattEvans16 Says:

    Works Great … 12.5GB down to 6.5GB (WinXP 32bit)

  21. UnidentifiedAnonymous Says:

    I compressed the vdi file with Winzip to a zipx file, and the resulting file was just “10%” of the original !!!!

    (NOTE: I compressed it for archiving since I was not, currently, using it)

  22. Erik Says:

    I went from 12GB to 5.3GB – and had a good laugh watching Windows twitch and squirm while its disk was filling up.

    Thanks for the article!

  23. Compact VDI Image file |, 像风一样自由 Says:

    […] Compacted my Windows XP 6GB VDI Image to 4GB  today according to this article. […]

  24. Anonymous Says:

    Works great for me, took a 20GB Windows 7 guest image running on Mac OSX host down to around 10GB. Took a while, but very worthwhile. Works fine on Virtualbox 4.0.12 (most current build as of today) so not sure what the comments were about it not working for others on earlier versions.

  25. Josh Justice Says:

    Mac OS X guests: the OS automatically does a lot of defragmenting for you–the two times I’ve shrunk an OS X image, I haven’t had to do any defragmenting. You can zero out your free space by opening Disk Utility, selecting your disk, going to the Erase tab, clicking Erase Free Space, then Zero Out Deleted Files.

  26. Mats Karlsson Says:

    VBoxManage switches has changed with Oracle:

    VBoxManage modifyvdi /media/Block/VDI/NewHardDisk1.vdi compact

    Changed to:
    VBoxManage modifyhd –compact /media/Blockk/VDI/NewHardDisk1.vdi

  27. dushy Says:

    I am on a window host and a novice user when it comes to commands and terminal. I had to search several other threads to get VBoxManage command to work. I am writing these steps to help other users like me.

    These are the steps to do the same in Window Host:

    1. Open cmd.exe
    2. type cd\ to go to root directory
    3. Go to virtual box directory (assuming you have installed on c drive) by typing cd C:\Program Files\Oracle\VirtualBox
    4. Type VBoxManage modifyhd -compact D:\xp.vdi (xp.vdi is name of my virtual disk in “D” drive. You can type your own address. Generally it is found in C:\Users\Dushyant\.VirtualBox\VDI)

    It will show progress and you are done.

    I reduced size of my xp disk from 9 gb to 4.3 gb

  28. Robert Says:

    Under windows, Oracle VirtualBox 4.2.10 this works

    “c:\Program Files\Oracle\VirtualBox\VBoxManage.exe” modifyhd Windows7.vdi –compact

  29. google Says:

    Hi! I’m at work browsing your blog from my new iphone 4!

    Just wanted to say I love reading through your blog and look forward to all your posts!
    Carry on the superb work!

  30. dcelso Says:

    if you have a guess windows SO yo can use the next command to remplace nullfile
    cipher /w:X where X is the letter of the drive

  31. dcelso Says:

    And use VBoxManage modifymedium “vdi path” –compact

  32. Raguel Lenske Says:

    the truth about it is possible to be extremely stable in the next days. France is the logical territory for btc to be used for currency

  33. Paykasa Says:

    Hi Guys.

    A quick pre-sales question.

    How would I make the portfolio section go from black and white to color on hover?

    Could this be done? Is it something you could help me with if I brought another license?

    Kind regards Hoey

  34. Benjamin Marwell Says:

    For all unix-based guests (*BSD, Linux, and Mac) you can just write a file full of zeroes. No need to download and compile some source files. You might not want to have to install a compiler anyway.

    Just do this:
    dd if=/dev/zero of=$HOME/zerofile.img bs=4m; rm /zerofile.img
    This will null your home partition by filling it with zeroes. If you have just one partition, you are done. If you have seperate partitions, figure those out using the mount command and repeat (replate $HOME with /path/to/partition).

    Also you should note: If you have encryption set up, this won’t work and might even be counterproductive. 00s encrypted are producing random scrambled data, which is in return uncompresseable.

    Hope that helps those running non-windows-guests.

    For Windoze (or Wintendo as some might say), you can also use various other tools you might already have installed, like the popular CCleaner.

  35. Margert Tafuri Says:

    I dugg some of you post as I thought they were very useful extremely helpful

  36. samsun escort Says:

    Mechanical forces play a central role in ubiquitous phenomena such as protein degradation, cell-adhesion, tissue organization, and muscle function in multi-cellular organisms. The key players in these phenomena are protein molecules, which act as mechanosensors and communicate the surrounding dynamic microenvironment with the cell. Hence, studying the mechanical response of these biomolecules would provide a wealth of information about their structure, function, and chemistry.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: