2

After I noticed WSL2 was always running on my PC I wondered what was going on and after I checked noticed Kali was running and didn't matter what I did it didn't stop also I tried to reinstall everything but that also didn't change anything.

So, I was wondering if anyone has a solution for this problem so Kali stops once the terminal window is closed.

This is after running wsl --shutdown command even. WSL2 Kali running

17
  • Can you show us some screenshots?
    – harrymc
    Commented Oct 9, 2022 at 13:52
  • @harrymc Well I added the WSL state is there a specific screenshot that you wanted
    – poqdavid
    Commented Oct 9, 2022 at 14:56
  • Kali not stopping is not normal. Is that the question? And what have you done to stop it? Screenshots will be useful.
    – harrymc
    Commented Oct 9, 2022 at 14:59
  • @harrymc Yes basically I want Kali to be the same as Ubuntu once the terminal is closed Kali should stop too and I reinstalled and repaired everything related to WSL2 also I tried wsl --shutdown and I didn't want to stop the services related to WSL2 because I do use WSL2 Ubuntu mainly
    – poqdavid
    Commented Oct 9, 2022 at 15:21
  • Does wsl --terminate kali-linux work?
    – harrymc
    Commented Oct 9, 2022 at 16:17

2 Answers 2

2

Let's take a different approach. This is still based on the theory in my previous answer, but a different way of trying to determine what's going on.

Since you have autoruns.exe already installed (from the comments), you may have the rest of the SysInternals Suite as well. If not, install it, or at least Procmon. Then:

  • Run procmon.exe
  • Filter -> Filter... (or Ctrl+L, or the icon)
  • Create a Path filter which contains \\wsl
  • Add the filter to the list, and Okay the dialog
  • Reset the display via the icon, Ctrl+L, or Edit -> Clear Display

Look for something accessing \\wsl.localhost\kali-linux\....

I ended up finding that, for some reason, Asus Armory Crate is attempting to access some old (no longer on my system) distributions including Kali. I'll be attempting to uninstall (and perhaps reinstall) to see if I can eliminate this. But I really have no idea why Armory Crate is doing this. Now I'm wondering if it could even be the same process on your system.

4
  • Fun fact I do have an Asus device and what you suggested is showing that ArmouryCrate.UserSessionHelper.exe is trying to access a file at this path \\wsl.localhost\kali-linux\usr\lib\win-kex\win-kex and since it doesn't exist it just fails its really surprising for me that process is trying to access Kali on WSL2
    – poqdavid
    Commented Oct 11, 2022 at 16:39
  • 1
    btw I did some more digging and as it turns out it's AC_FDSPlugin that's causing all that not the whole process
    – poqdavid
    Commented Oct 11, 2022 at 17:35
  • @poqdavid Well first, woohoo! Glad we found it. And amazed that this Asus process/plugin hasn't been noticed before in relation to WSL. Is there a way to remove just that plugin that you've found? Commented Oct 11, 2022 at 17:54
  • 1
    Yah true this is very surprising to me also and I just renamed the plugin in C:\Program Files\ASUS\ARMOURY CRATE Service\AC_FDSPlugin and it's all fine but also at the same time not sure what that plugin does and also I found this reddit.com/r/ASUS/comments/i0712x/… looks like that plugin scans network drives for some reason xD
    – poqdavid
    Commented Oct 11, 2022 at 18:23
3

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.

11
  • I have WSL2 0.66.2.0 do I need to get 0.68.4?
    – poqdavid
    Commented Oct 10, 2022 at 14:54
  • 1
    @poqdavid If you have 0.66.2.0, then it already has the debugShell feature -- No need to go to 0.68.4 unless you want to. If you do, see the instructions I provide in this post, but just skip the part about enabling Systemd (unless you want that as well). Commented Oct 10, 2022 at 16:27
  • Well I did what you said and WSL2 started right after I logged in to my account before anything else, like that was the first thing that came on my screen also my startup is very clean and I am sure the startup isn't the cause
    – poqdavid
    Commented Oct 10, 2022 at 22:29
  • @poqdavid It freaked me out when it happened, and took me a while to figure out what process had it. You might want to load up Autoruns from the SysInternals suite (owned by Microsoft for quite a few years now). It can show you everything that runs at boot to see if something might make sense. Commented Oct 10, 2022 at 23:17
  • 1
    Also, I just noticed when I switch to different applications the WSL2 Kali restarts itself which I didn't know that until I enabled the option you mentioned and it's not a specific application it's just any application in general
    – poqdavid
    Commented Oct 11, 2022 at 11:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .