2

I have a virtual machine, that has dynamically expanding vhdx as a C drive. Or 'thin provisioned' to speak in terms of other hyper-visors.

I'm running Windows server 2016 on it, as a DC to be exact. Over the time of two years the vhdx file grew; the size of the disk within the virtual machine lists as 18gb, while the vhdx file is around 128gb. The vhdx is to big.

What caused this?, and how can I shrink the size of the vhdx file.

Dennis
  • 529
  • 1
  • 7
  • 18

1 Answers1

3

After a few days of trying several things, a combination of the following helped to shrink the vhdx file;

  1. In the virtual machine; properties of the drive, do a disk clean up, reboot
  2. Open an powershell as admin and do a: Optimize-Volume -DriveLetter C -Defrag -Verbose
  3. In the same powershell do a; Optimize-Volume -DriveLetter C -ReTrim -Verbose for some wierd reason, I had to repeat these steps a few times. Once it even crashed.
  4. Shut down the virtual machine, and in the hyper-v manager; go to the virtual machine, go to the virtual disk. Edit, choose action; compact.

Finally, the vhdx file was around the size of the actual data on it. I hope this helps others!

Dennis
  • 529
  • 1
  • 7
  • 18