Hacker News new | ask | show | jobs
by tonymet 99 days ago
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
2 comments

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.

you can try doing fstrim + Optimize-VMD first . i've found it is good up to 20% savings. On my last run my 75 gb wsl disk saved about 15gb. But wiping and re-installing trimmed about 60 gb
"delete the VM, create a new one, reverse the process.

   $ tar -cxf /mnt/c/Temp/home-backup.tgz -C $HOME"
That's not going to bring much joy.
it's illustrative