Shrinking VirtualBox VDI Files

Source: http://garethtuckercrm.com/2012/07/25/shrinking-virtualbox-vdi-files/

 

1. Ran Disk Defragmenter within the VM and defrag’ed the disk. 

2. Ran TreeSize Free within the VM to check for large files/folders that I could trim (didn’t find anything, but did notice the winsxs folder was huge, so did some research on that…)

3. Ran the DISM command line below to purge the winsxs folder (removes data that resides on your disk to enable rollback of service packs, makes your service packs permanent – do a bit of research on this before you decide to do this)

Here’s what I ran:

clip_image002

This reduced the size of C drive inside my VM by 5GB. I think the results you get will depend upon the initial level of your OS and the number of updates you have installed over top.  There seems to be different clean up utilities like this for different OS’s and Service Packs.   I’m no expert on this though.  I ran this over a Windows 2008 R2 SP1 Enterprise Edition install. 

4. Downloaded sdelete to the C drive of my VM and then ran from a command prompt the following command (from c:\ ) sdelete -c -z C:\

This will write 0’s over any unused space on your VM hard disk.  This makes it crystal clear that that unused space can be purged.

5. Shutdown my VM.

6. Opened a command prompt on my host machine and changed directory over to the VirtualBox program folder (C:\Program Files\Oracle\VirtualBox).  Ran the following command to ask VirtualBox to compact my VM’s VDI file:

VBoxManage modifyhd –compact “D:\<path>\<filename>.vdi”

That’s it.   Oh, and the VM still launched afterwards Smile

 

You may also like...

Leave a Reply

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