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. http://www.feyrer.de/g4u/nullfile-1.02.exe : 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.
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






December 18, 2008 at 12:03 am
[...] VirtualBox – Shrink your VDI images [...]
February 1, 2009 at 9:29 pm
[...] http://kakku.wordpress.com/2008/06/23/virtualbox-shrink-your-vdi-images-space-occupied-disk-size/ (31) [...]
February 7, 2009 at 9:05 pm
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.
February 21, 2009 at 7:56 am
[...] Ссылки по теме: • 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 • Скачать qemu-0.7.1-win32-imgover4g.zip • 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 [...]
March 31, 2009 at 10:41 pm
[...] http://kakku.wordpress.com/2008/06/23/virtualbox-shrink-your-vdi-images-space-occupied-disk-size/ (101) [...]
April 2, 2009 at 12:09 pm
Here is some related discussion with a few work-arounds:
http://forums.virtualbox.org/viewtopic.php?p=59796#59796
April 15, 2009 at 12:53 pm
Apparently, using the clonehd command will shrink your vdi when it copies it, so that should be the simplest workaround out there.
June 13, 2009 at 5:21 pm
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?
Thanks!!
July 15, 2009 at 9:11 pm
For Windows Guests.. You can download SDelete utility from Microsoft to zero unused space with the option -c from here:
http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx
Then you can use the following command from the Host OS..
VBoxManage modifyhd –compact
October 20, 2009 at 7:19 am
Duear Majed Sahli,
sorry if i make such a dumb question, but it’s my first time:
the sDelete utility should be downloaded and run into the virtual machine?
Thanks
November 1, 2009 at 11:22 pm
Yes
August 31, 2009 at 12:35 pm
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,
Cheers
September 2, 2009 at 10:50 pm
[...] จาก http://kakku.wordpress.com/2008/06/23/virtualbox-shrink-your-vdi-images-space-occupied-disk-size/ [...]
September 17, 2009 at 11:45 am
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?
October 23, 2009 at 12:13 pm
[...] 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 vdihttp://kakku.wordpress.com/2008/06/23/virtualbox-shrink-your-vdi-images-space-occupied-disk-size/ [...]
November 9, 2009 at 1:14 pm
and which version of vbox are we talking about ?
-Regards,
techspalace.blogspot.com (not only Ubuntu blog)