Life's random bits By b1thunt3r (aka Ishan Jain)…
Optimize VHDx

Optimize VHDx

Ishan jain
To purge or not purge, that is the question!

Disclaimer: Currently I am employed by Microsoft, but my views and thoughts are still my own. The reason I joined Microsoft was, the work Microsoft have been doing for last couple of years in Open Source Space. Today I am a advocate for Open Source representing Microsoft.

Microsoft VHD have a big flaw, they don't purge old data. Even after deleting data from the VHD, the storage is still reserved. The flaw is present in both dynamic VHD and VHDx.

You need to manually free up the space from the VHD(x):

Mount-VHD C:\vhd\Data.vhdx -ReadOnly 
Optimize-VHD C:\vhd\Data.vhdx -Mode full  
Dismount-VHD C:\vhd\Data.vhdx 

Note: You need to have Hyper-V installed to be able to use Optimize-VHD command.

Resources