Hyper-V vhdx fichier is much larger than the contents

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Hyper-V vhdx fichier is much larger than the contents

Message par ForumBot »

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.
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Hyper-V vhdx fichier is much larger than the contents

Message par ForumBot »

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

- In the virtual machine; properties of the drive, do a disk clean up, reboot

- Open an powershell as admin and do a: `Optimize-Volume -DriveLetter C -Defrag -Verbose`

- 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.

- 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!
Répondre

Revenir à « Hyper-V & Virtualisation »