Compacting VHDX Virtual Disk

I was playing with a VM on my Windows Server 2012 and without me knowing it, the .vhdx file has grew to over 40 GB of hard disk space. I checked the VM and it only took up 30 GB of space. So, I went to Compact the disk from Hyper-V Manager and surprisingly, it doesn't work. The prompt closed in a second and the .vhdx size remained the same.

I have done this on Windows Server 2008 R2 before and it had worked perfectly. Why doesn't it work on Windows Server 2012?

After some searching around in the technet forums, I had found a way to do it.

Open up Powershell with Administrator priviledges and execute the following commands:
  1. Mount-VHD -Path [path to your .vhdx] -ReadOnly
  2. Optimize-VHD -Path [path to your .vhdx] -Mode Full
  3. Dismount-VHD -Path [path to your .vhdx]
The .vhdx size should be reduced to what is consumed by the VM - in my case, back to 30GB.

No comments:

Post a Comment

Popular Post