VirtualBox Windows guest VDI hard disk shrink/reduce - Host and Guest: Windows

Addet at:Sun, Dec 13, 2020 Updated at:Sun, Sep 15, 2024

VirtualBox hard disks (VDI, VMDK or VHD) bloat over time. This is because the Virtual Machine Monitor does not automatically reduce the size of the virtual disk when files are deleted on the guest system. This has a useful background. In short, it prevents frequent access to the hard disk, which benefits the life of the hard disk. It is nevertheless possible to reduce the size of virtual hard disks (VDI, VMDK or VHD). VirtualBox provides a tool for this purpose.

In this article you will learn step by step how to reduce or shrink a Windows guest VDI disk.

1.0 The system cleanup - Step 1/3

1.0 Vorab Clean guest system (Windows)

It makes sense to clean the guest system of unnecessary files and programs beforehand, i.e. delete files from the download folder, for example, or uninstall unnecessary programs, empty the trash, etc.

2.0 Prepare hard drive with SDelete - Step 2/3

1.1 Install Windows Tool SDelete

On the Windows guest system, the Microsoft Windows program SDelete must be downloaded and unpacked SDelete (Download)

1.2 SDelete execute

Now open Powershell (or cmd.exe) on the guest system and navigate to the directory where you saved the SDelete tool.

Tip: Press [Shift] + [right mouse button] in the SDelete directory and then click on "Open PowerShell window here". This will open PowerShell in the corresponding directory.

Now run the following command in PowerShell to complete the first process (rewriting unused blocks to zero). If you have a 32-bit system, use sdelete.exe instead of sdelete64.exe. Normally, everyone uses Windows 64Bit. You can check the system information in Windows with [Windows key] + [Pause] (system type).

$ sdelete64.exe c: -z

With a hard disk size of about 30 GB, this process takes about 5 minutes (animation is accelerated):

3.0 Perform VDI downsizing - Step 3/3

2.1 Effectively shrink the VDI file/hard disk with VBoxManage

Now comes the final part. Here the VDI file, i.e. the VDI hard drive, is actually reduced in size.

To do this, open Windows PowerShell on the host and navigate to the VDI file. Now execute the following command in PowerShell to start reducing/shrinking the VDI file. Please note: The & sign must also be entered at the beginning. The $ sign does not.

$ & 'C:\Program Files\Oracle\VirtualBox\VBoxManage.exe' modifymedium disk '.\Windows 10.VDI' --compact

For a ~31 GB VDI hard drive, this process takes about 5 minutes. The result should look like this:

That's it, the VDI file/hard drive has been successfully shrunk or reduced. An example of what the result might look like:

Before: 31 GB
After: 11 GB