Oracle VirtualBox is one of the most popular software for creating Virtual Machine (VM). It saves our entire client OS in a HDD image file (VDI format). If you use dynamically allocated file size, your VM image fie will start small, then grow as you use your client OS. The problem is, when you delete a big file inside your client OS, the VM image file size does not reduce. By normal usage, it can only grow, up the maximum size you have defined in first creation.
If you are using a desktop computer with large internal storage, you might never care about several extra gigabytes. But if you’re using one of those computing devices using SSD (solid state disk) as the only internal storage (such as Macbook Air or Microsoft Surface), then few gigabytes is very valuable space, and doing some steps to reduce the file size might worth the trouble.
There is a way to actually reduce VDI file size without harming your client OS. These simple steps will help you to save significant space in a VDI file containing Windows client OS.
1. Open VirtualBox and run the client OS (this guide will only works if the client OS is Windows).
2. Do some cleanup (uninstall unnecessary applications, delete unused files, clean up temporary files, etc). You might want to run Windows Disk Cleanup tool.
3. Perform Disk Defragmenter.
4. Download this small application called sdelete.
5. Extract the application to your user folder, then open command window and type sdelete -z c: (this will put zero bits on your unused space).
6. Shut down your Windows client OS and close VirtualBox.
7. Execute the following command in your host OS: VBoxManage modifyhd my.vdi –compact (replace “my.vdi” with the path and filename of your vdi file). If your host OS is Windows, type it in command prompt. If your host OS is Mac, open Terminal and type the command. This command has been tested in VirtualBox 4.2.6 and works perfectly. Future releases of VirtualBox might change the syntax though.
8. Done, check your VDI file size now.
Tested on Mac OSX 10.8.2 Mountain Lion (host OS) with Windows XP Home Edition (guest OS) using VirtualBox 4.2.6. Different OS or different VirtualBox version might produce different outcome. Use this guide at your own risk.
sdelete -z c: doesn’t work in Windows XP Home Edition (installed as a VirtualBox guest on a Linux host pc). It gives error message that “C is not a valid drive for the operation, argument must be d:” Perhaps sdelete has to installed on a bootable disk, then reboot the guest to that disk, and run it from there?
win7 x86
15.3 -> 12.8
Now is show this message: “‘modifyhd’ is not recognized as an internal or external command, operable program or batch file.”
I type the command in cmd but it show this massage: “‘VBoxManage’ is not recognized as an internal or external command, operable program or batch file.”
I think is the path, but I don’t know what path in cmd I need to write down the command
Thanks mate. Worked perf
PERFECT!
9GB to about 6GB!
Thank you!
Wow, worked like a charm, 13GB to 8GB! Thanks for the straightforward non-technical instructions!
This is awesome, let’s give it a try, thank you for sharing.