this is great and I have a feature request: A "refresh VM" feature that exports your home dir + packages into a new VM instance.
I've tried Optimize-VHD but renewing the VM this way frees up disk and speeds up the VM as well. None of the WSL settings for sparse disk / disk shrinking seem to work well.
Here's what I usually do
$ tar -czf /mnt/c/Temp/home-backup.tgz $HOME
$ apt list --installed > /mnt/c/Temp/packages.txt
delete the VM, create a new one, reverse the process. $ tar -cxf /mnt/c/Temp/home-backup.tgz -C $HOME
$ apt update
$ cat /mnt/c/Temp/packages.txt | xargs apt install
You operate a little cleaner than I do- there are invariably things that end up in /usr/local/bin..
Still, thanks for the process you use.
My wsl is pretty long lived now, through quite a few ubuntu upgrades and installations of stuff that I probably no longer need.