0

so, i'm running my wsl on windows 10, and when I type:

sudo -u root init 0 i get the error:

Couldn't find an alternative telinit implementation to spawn.

Neofetch ( no flags or args ):

       _,met$$$$$gg.          linx@win64
    ,g$$$$$$$$$$$$$$$P.       --------------------------
  ,g$$P"     """Y$$.".        OS: Debian GNU/Linux 11 (bullseye) on Windows 10 x86_64
 ,$$P'              `$$$.     Kernel: 5.10.102.1-microsoft-standard-WSL2
',$$P       ,ggs.     `$$b:   Uptime:------------
`d$$'     ,$P"'   .    $$$    Packages: 245 (dpkg)
 $$P      d$'     ,    $$P    Shell: bash 5.1.4
 $$:      $$.   -    ,d$$'    Terminal: /dev/pts/1
 $$;      Y$b._   _,d$P'      CPU: Intel i5-8250U (8) @ 1.799GHz
 Y$$.    `.`"Y$$$$P"'         Memory: 99MiB / 6225MiB
 `$$b      "-.__
  `Y$$
   `Y$$.
     `$$b.
       `Y$$b.
          `"Y$b._
              `"""

The same thing happens when I try:

su root

and try again

1
  • What research have you done and what have you tried? What is the actual problem here? What do you expect to happen when you run this? What are you trying to accomplish by running the command? Sep 12, 2022 at 3:53

1 Answer 1

0

I'm assuming that you are trying to shut down Debian under WSL with a telinit 0 (as root). That just won't work for several reasons:

  • Despite being named /init, WSL's init process is not a SysV Init that has the concept of runlevels.

  • Under Debian, telinit is a symlink to the Systemd systemctl anyway. From the telinit manpage under Debian:

    Since the concept of SysV runlevels is obsolete the runlevel requests will be transparently translated into systemd unit activation requests

    And that's not going to work either, since WSL doesn't support Systemd without additional (typically not recommended) configuration. See this Ask Ubuntu question and this Super User question for more details there.

Debian running under WSL is very similar to running Debian in a Docker container (reference Are Windows WSL2 "distributions" just docker containers under the hood? here on SU). Inside a container, there's just no concept of a "shutdown". That needs to be handled from the host (WSL itself).

So there are perhaps two real questions in your question that you didn't ask:

  • How to shutdown Debian under WSL?

    You have two options. First, you can terminate just one particular distribution with wsl --terminate <distroname> (probably wsl --terminate debian for you). Or you can terminate all distributions, and the managed host VM (under WSL2, that you can't typically "see") with wsl --shutdown).

    You can even run this from inside Debian with wsl.exe --shutdown.

    However, note that this is not a "clean" shutdown. Processes inside are not notified in advance and given the chance to "clean up" with a SIGTERM. Which leads us to the next question ...

  • How to shutdown processes in Debian under WSL safely?

    This isn't as easy as I'd like. But without a WSL mechanism itself to rely on, the best alternative may be to use a process/service manager to launch and manage any processes that you need to safely shut down.

    I've had good success with Supervisor in the past. You can set it up to start, manage, query, stop (etc.) services.

    If you were running all services under Supervisor, then you could, in effect, shut down Debian under WSL via:

    wsl -u root -e supervisorctl stop all
    

    Once all processes inside Debian have terminated, WSL will automatically terminate the instance after 15 seconds. Another 10 seconds (by default) after that, and WSL2 will "shutdown" the VM itself.

You must log in to answer this question.

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