Skip to content

VM disks on Windows: VDI, VMDK and the snapshots behind them

Virtual disks grow and stay grown, and suspended machines write a file the size of their memory. The compaction commands for both.

6 min read

A virtual machine is the largest thing most developers have on a drive, and the file is almost never the size the guest reports. It grows to the high water mark of everything the guest has ever written, and it stays there.

What is in a machine folder

ExtensionWhat it isTypical size
.vdi, .vmdk, .vhdThe virtual disk20 to 200 GB
.vmem, .vmss, .savSuspended machine memoryThe guest's RAM, exactly
Snapshots\*.vdi, *-000001.vmdkPer snapshot change filesGrows while the snapshot lives
.nvram, .vbox, .vmxConfigurationKilobytes
# Every VM folder on a drive, largest first
Get-ChildItem 'D:\VMs' -Directory -EA SilentlyContinue | ForEach-Object {
  $s = (Get-ChildItem $_.FullName -Recurse -Force -File -EA SilentlyContinue |
        Measure-Object Length -Sum).Sum
  [PSCustomObject]@{ GB = [math]::Round($s/1GB,1); Modified = $_.LastWriteTime; Name = $_.Name }
} | Sort-Object GB -Descending

Sort that by Modified instead and the answer is usually immediate: two or three machines nobody has booted in a year, holding more than everything else in the folder combined.

Shrinking a VirtualBox disk

  1. In the guest, delete what you meant to and write zeros over the free space. On Windows guests sdelete -z C: does it, on Linux guests filling a file with zeros and deleting it does the same.
  2. Shut the machine down completely, not saved.
  3. Compact with VBoxManage from the host.
  4. Fixed size disks cannot be compacted at all, which is the trade you accepted when you created one.
VBoxManage modifymedium disk "D:\VMs\dev\dev.vdi" --compact

# Snapshots, which are usually the larger number
VBoxManage snapshot "dev" list --details
VBoxManage snapshot "dev" delete "before upgrade"

Shrinking a VMware disk

# With VMware Tools installed in the guest, from the guest
# (VMware Tools, Shrink tab, or the command below on Linux guests)
vmware-toolbox-cmd disk shrink /

# Or from the host, machine powered off
"C:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager.exe" -k "D:\VMs\dev\dev.vmdk"

Workstation also offers Manage, Clean Up Disks in the user interface, which runs the same operation and reports what it expects to recover before you commit.

Snapshots are where the real growth is

A snapshot redirects new writes to a separate file. Keeping one for a week costs little; keeping one for a year means every change since is stored separately, and the chain can exceed the original disk several times over. Deleting a snapshot merges it back and keeps your current state.

The suspended machine nobody thinks about

Suspending a machine with 16 GB of memory writes a 16 GB file. Three suspended machines is 48 GB that no guest reports and no disk image explains. Shutting them down properly rather than suspending returns all of it.

If the machine also runs containers or WSL, Hyper-V disks and checkpoints covers the same problem in the Microsoft format, and the layout that avoids all of it is in storage for a Windows dev machine.

Common questions

Why is my VirtualBox VDI so large?

Because a dynamically allocated disk grows to the most the guest has ever used and never shrinks on its own. Zero the free space inside the guest, shut it down, then run VBoxManage modifymedium with --compact.

How do I shrink a VMware disk on Windows?

Use the Shrink option in VMware Tools from inside the guest, Manage then Clean Up Disks in Workstation, or vmware-vdiskmanager -k against the vmdk with the machine powered off.

Do VM snapshots take up much space?

They are usually the largest part. Every write after a snapshot is stored separately, so a snapshot kept for months can exceed the size of the original disk. Deleting it merges the changes back.

What is the .vmem file in a VM folder?

The suspended machine's memory, written to disk at the size of the guest's RAM. Shutting a machine down instead of suspending it removes the file.

Read next