WSL handy commands
Often WSL2 does not work well anymore, and those commands have saved me some time and headaches.
If you have messed-up something (e.g. sudo), login to the WSL as root (from windows CMD)
C:\>wsl -u root
Restart WSL2, sometimes needed when you can't connect from your windows to the servicess runing on it (e.g. to access a localhost website running on WSL)
C:\>wsl --shutdown
Increase limit of open files
WSL does not support to do it the usual way, so this is what it works for me (ubuntu and WSL2). Source: https://github.com/microsoft/WSL/issues/4575
$ mylimit=200000
$ sudo prlimit --nofile=$mylimit --pid $$; ulimit -n $mylimit
In case of panic
If things are very very wrong, and wsl
does not respond, not even with restarts. Try this
How do I troubleshoot an unresponsive WSL2 on Windows 10?
Usually, WSL2 runs fine, but maybe once a month or two, it becomes completely unresponsive and I’m not sure why. Usually restarting the entire computer fixes it, but I’d like to know if there is an…
With admin permissions on a powershell:
taskkill /F /IM wslhost.exe
taskkill /F /IM wsl.exe
taskkill /F /IM wslservice.exe
net stop LxssManager
net start LxssManager
net stop vmcompute
net start vmcompute
net stop hvhost
net start hvhost
And restart the computer