Hyper-V vhdx file is much larger than the contents
Solution 1:
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!