virtualboxOracle 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.