I came across a situation to shrink VirtualBox vdi file having my Windows 10 virtual machine. My host is MacOS Sierra.
The vdi file size grew rapidly while I was doing data manipulation in SQL Server database in Windows 10. Even after shrinking the database size in windows, the vdi file was not reducing in size. So, I’ve done the below steps to manually shrink the size of the virtual machine vdi file.
I thought of publishing the steps to shrink virtualbox vdi on mac with windows guest, so as it may be helpful for someone else.
Software & Tools Involved
- Host OS: MacOS Sierra
- Hypervisor: VirtualBox 5.0.26
- Guest OS: Windows 10
- SDelete V2.0
Steps to Shrink VirtualBox Vdi On Mac OS
- Check the free space in Windows 10 and the size of the virtual machine vdi file.
- Login to the Windows 10 guest OS.
- Perform a disk cleanup using the Disk Cleanup tool.
- Once the disks are cleaned, you have to zero out the free space. To zero out the free space, use the SDelete tool. Download the SDelete V2.0 from Windows Sysinternals. Extract the downloaded SDelete.zip file. You will see 2 executables sdelete.exe and sdelete64.exe. One for 32-bit os and another for 64-bit os.
- Open Command Prompt and go to the folder where you have extracted the SDelete files.
- Execute the command “sdelete64 -z c:” to zero out the free space in the windows virtual machine. Wait till the cleaning free space process reach 100%. (NOTE: I’ve used the 64-bit version of SDelete and my Windows 10 is 64-bit)
- Now, shut down windows 10
- Open Terminal in host MacOS.
- Execute the virtualbox manage command “VBoxManage modifyhd <>> –compact”. Instead of <<<vdi file path>>> use the full path of the location of VDI file.
- Wait till the compact process reaches 100%.
- Check the size of the vdi file. In my case, I’ve gained more than 21 GB of free space.
Refer https://technet.microsoft.com/en-us/sysinternals/sdelete.aspx for more details on using sDelete.