I booted up the linux machine in a rescue environment then ran this command:
fstrim /
This did not take long to complete. Once it was done I shutdown the VM
On the Hyper-V server in powershell I then ran this command to start the compact:
Optimize-VHD C:\VM\yourvmvhd.vhdx -Mode Full
Reference:
https://www.altaro.com/hyper-v/compact-vhdx-linux-filesystem/