Quantcast
Channel: Active questions tagged windows-subsystem-for-linux - Ask Ubuntu
Viewing all articles
Browse latest Browse all 2930

WSL /dev/console, /dev/ttyN, /dev/vcsN and /dev/hvc0

$
0
0

In WSL, writing to /dev/console goes nowhere apparent. What happens to things written there? This question is generally to clarify the role of virtual consoles in WSL and hvc0.

A 2010 post with no responses asks

I would like to get some information regrading the hvc0 terminal. A search on the web hasn't came with useful stuff.

And it is thinly discussed in any StackExchange questions; one of the only is https://unix.stackexchange.com/questions/10857/what-is-hvc0-appearing-in-who-list

In Ubuntu running on Virtualbox,

virtualbox$ cat /proc/consolestty0                 -WU (EC  p  )    4:3virtualbox$ echo hello | sudo dd of=/dev/console status=nonehello                                                                                                                                           virtualbox$ echo hello | sudo dd of=/dev/tty0 status=nonehellovirtualbox$ tty/dev/tty3virtualbox$ fgconsole3virtualbox$ cat /sys/class/tty/tty0/activetty3                                                                                                                                               virtualbox$ echo hello | dd of=/dev/tty3 status=nonehellovirtualbox$ sudo cat /dev/vcs3 > out

The above session typescript is made with the last command in it.

In WSL, writing to /dev/console goes nowhere apparent. If the answer is to run strace, like

echo hello | sudo strace dd of=/dev/console

where is the "interesting" part of the output, which is a bunch of UTF stuff, mmap, fstat, open and close.

There is no /dev/tty0 or /dev/vcs0, but instead /dev/hvc0.

wsl$ cat /proc/consoleshvc0                 -W- (EC p  )  229:0

In WSL, despite not being able to access virtual consoles like in usual Linux, we can write and read to them:

wsl$ echo hello | sudo dd of=/dev/tty1 status=nonewsl$ sudo cat /dev/vcs1Ubuntu 24.04.3 LTS laptop tty1                                                                                                                                  laptop login: hello

The following seems to mean that tty1 is "populated" with a login screen (by systemd getty?), that is we can see the login by reading /dev/vcs1 but we see nothing reading /dev/vcs2.

wsl$ cat /sys/class/tty/tty0/activetty1wsl$ fgconsoleCouldn't get a file descriptor referring to the console.

However we can indeed write to /dev/tty2 and then read from /dev/vcs2:

wsl$ echo hello | sudo dd of=/dev/tty2 status=nonewsl$ sudo cat /dev/vcs2hello

Viewing all articles
Browse latest Browse all 2930

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>