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:
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:\VirtualBox\CRM 2011 on SQL 2008 DEV Image\Hard Disk\CRM2011 DEV Image (64-BIT Win2008R2 SQL2008R2).vdi"
That’s it. Oh, and the VM still launched afterwards ![]()

Cool instructions, thanks dude.
I don’t think that DISM is available for XP/2003/etc systems. It’s worth noting, I guess, then if it’s been decided to run the older OS for its smaller footprint.
I question the use of -c in sdelete. Is it important to clean the free space before zero-writing it? That command switch seems to be important for security. In this situation however, we’re zero writing, and then the dynamic VDI file is being truncated.
If the VDI won’t truncate without the -c, by all means it’s important to include it here. I haven’t tested that yet (i’m following your instructions verbatim).
If the user is interested in the concept of security, then it would be best looking at the underlying filesystem, such as ext4 secure delete (if your virtual systems are inside a linux host), or confirming use of ‘discard’ options when using SSD drives.
Just shrunk a 117 GB VDI down to 35 GB. I had actually ran out of space on the host drive. Running the VBoxManage modifyhd –compact by itself initially game me 700mb free space, which was enough to allow me to boot the VM and then complete the steps in this post. Thought I was stuffed. Phew!
Better do step 1 just before step 5 not at the beggining
Before step 4 i mean.