Short answer: Something in Windows may be attempting to access a file in \\wsl.localhost\kali-linux
. Whenever the path is accessed, the distribution will start, at least on Windows 11.
More detail:
I recently had a similar situation myself, but I don't know for sure that you are running into the same thing.
In my case, I had:
- Multiple distributions installed
- One of them was a specialized Debian distribution with a local Stable Diffusion installation
debugShell=true
set in .wslconfig
. This is a feature in WSL releases 0.51.2 and later that displays a separate debug shell whenever the WSL2 VM starts (or restarts).
I was noticing the debug shell (and thus the WSL2 VM) was starting up when I wasn't doing anything WSL related, usually shortly after booting Windows. Then I noticed that it was happening when I launched by browser, Vivaldi. And the only distribution that was starting up was the Stable Diffusion one.
If I renamed the distribution (via registry hack), it would no longer start. If I named it back, it would start whenever starting Vivaldi.
I finally tracked it down to the fact that I had downloaded a file (the Stable Diffusion) checkpoint using Vivaldi directly into the distribution using the \\wsl.localhost\<distro>
path. When Vivaldi was starting, I believe it did a quick scan of each file in the list to see if it still existed. This action caused the distribution to start.
In your case, you mention that Kali is restarting even immediately after closing it, which I'm assuming means that something has a file open in Kali and is trying to reopen it when it gets closed (the distribution stops).
If you have Windows 11, you can install a Preview release from the Microsoft Store to get that "visual indication" of exactly when Kali is starting. Create or edit %userprofile%\.wslconfig
(that's your Windows profile, not WSL) with the following:
[wsl2]
debugShell=true
Then wsl --shutdown
. The next time Kali starts on its own, you'll see a debug console window. You don't need to do anything with it -- It will just be a visual indication that Kali started. You can just close it out when it appears.
I'm hoping that might give you some indication of exactly when Kali is starting, and based on that, perhaps what is causing it.
wsl --shutdown
and I didn't want to stop the services related to WSL2 because I do use WSL2 Ubuntu mainlywsl --terminate kali-linux
work?