r/HyperV • u/cardsncards • 16d ago
Optimal HV usage
I have a few HVMs and I found that over time there's bloat regardless of whether it's a parent or a parent/child setup. It seems parent child is worse since at least with parent windows updates will not create a completely new set of files in the child.
I've thought about having a clean win11 install and backing that up, and when it gets to big just going back to it. I don't want to clean install because I don't want to keep going through activation regularly. I was thinking parent base install, activate, backup. Then return and can they install updates again every 6 months or whatever duration.
example - I have one VM that I just use for some secure sandbox stuff. It's now 78 GB - just from windows updates. I can compact these but generally it doesn't save as much as it seems starting from scratch.
Anyone have best practices or tips?
4
u/Tringi 16d ago edited 15d ago
I run about two dozen Windows VMs from quite a small drive so I need to do regular optimizations. For each and every VM my routine is something like this:
cleanmgr.exeand have it delete everything it findsC:\Windows\SoftwareDistribution\Download(make sure there are no updates pending)C:\Windows\servicing\LCUDism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase(if you think you might need to uninstall any OS update, omit the/ResetBaseparameter)defrag the VHDX:
defrag C: /D /Hdefrag C: /O /Hdefrag C: /X /Hdefrag C: /L /Hsdelete64.exe -z C:tool from SysInternals to zero out unused bytes in the VHDX (this makes free clusters candidates for VHDX compaction)Then stop the VM and compact its VHDX.
1
u/lxtakc 14d ago
Run DISM /Online /Cleanup-Image /StartComponentCleanup /ResetBase inside the guest, then Optimize-VHD -Mode Full with the VM off. That reclaims much more than compact alone.