2

I am using Ubuntu 20.04 in the Windows subsystem for Linux on Windows 10. When I type the who command I get no output:

renniej@ratitch:~$ whoami
renniej
renniej@ratitch:~$ who
renniej@ratitch:~$

I have tried various things like sudo who and who -a but still I get no output. who --version gives:

who (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Joseph Arceneaux, David MacKenzie, and Michael Stone.

Am I doing something silly here? Or is this a feature of WSL2?

1 Answer 1

3

Short answer

Nothing silly. There's a Github issue related to the root cause. While the WSL team originally tagged it "by design" and "feature", there was activity on it last year that indicates that it is "high value low cost."

Then again, more recently it's noted that it was created 5 years ago, and has no "thumbs up" from other users wanting it fixed. My guess is that this won't be changed until and unless WSL adopts a more Systemd-like approach to startup (see below for details).

Explanation

... or more than you probably ever wanted to know about who

There are two reasons why who isn't showing any results:

  • First, the obvious -- who is designed to show (quoting from the man page), "who is logged in". When you start WSL, it doesn't actually send your user through the login password, which is the reason you don't get asked for a password.

  • Second, WSL runs its own /init process as PID1 at startup, which does the "magic" of setting up things like:

    • the Linux network being able to piggyback on the Windows network
    • the auto-mounting of Windows drives
    • the interop that allows Windows .exe's to run
    • and more ...

    A "normal" Linux system, on the other hand, starts up with Systemd or SysVInit (or a smattering of other init systems over the years). The init system is responsible for establishing the runlevel, among other things. And along with that (I'm just learning this myself from that Github issue), the /var/run/utmp construct, which is what tracks who is using the system.

There are a few ways that you could "force" who to work:

  • The first is covered in that Github thread. First, hack a /var/run/utmp with something like:

    sudo bash -c "echo '[1] [00049] [~~  ] [runlevel] [~           ] [4.4.0-17115-Micoroso] [0.0.0.0        ] [Wed Feb 28 13:27:14 2018 STD]' | utmpdump -r > /var/run/utmp"
    

    Then, force a "login" with sudo login -f $USER. You can then see your user logged in using who. If you were to login again via ssh (you'd need to set it up first), then that login would also appear.

  • You can now run Systemd under WSL using WSL release 0.67.6 or later as detailed in this answer, but you'll still need to force a login (as above) most likely..

  • Finally, you could manually start Systemd in its own PID namespace:

    sudo -b unshare --pid --fork --mount-proc /lib/systemd/systemd --system-unit=basic.target
    

    Wait a few seconds for Systemd to start up, and it will initialize /var/run/utmp. Technically at this point you can sudo login -f $USER and see who.

    Note that Systemd isn't fully usable without additional effort (beyond the scope of this answer), and that you must terminate the Ubuntu WSL instance after doing this in order to return to a stable state. Exit WSL and then wsl --terminate <distro> (where <distro> is likely ubuntu). Once you start back up, everything will be back to normal.

You must log in to answer this question.

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