Archive
How to compact VirtualBox’s VDI file size?
Problem
I had a Windows 10 in VirtualBox. I gave it a dynamic VDI file of size 100 GB. The file was about 50 GB large. When I upgraded it to Windows 11, the installer downloaded about 30 GB stuff, thus the VDI grew to 80 GB. After the upgrade, I cleaned the system and managed to go back to 50 GB inside Windows. However, the VDI file doesn’t shrink, it remained 80 GB. So I lost 30 GB free space. How to get it back?
Solution
I found the solution here. In short: fill up the empty space with zeroes and then ask VirtualBox to compact the VDI file. During this process, empty space filled with zeroes can be removed. This way I could reduce the size of my VDI file from 80 GB to 50 GB.
Steps:
- I didn’t defrag my Windows. As I know, NTFS defrags itself regularly. I skipped this step.
- Fill free space with zeroes. Download the tool sdelete and run it inside Windows. Open a terminal in admin mode and issue this command:
sdelete64 -z C: - Shut down the Windows system (the guest).
- In the host (I have Linux), issue this command:
VBoxManage --compact Windows10.vdi
It’ll reduce the size of the VDI file. After that, start your Windows box.
Before starting this process, I made a backup of my virtualboxed Windows, but there was no problem.