How can I find which physical device /dev/console connects to?
I think /sys/devices/virtual/tty/console/active
is what you're looking for.
Related videos on Youtube
user1937358
Updated on June 04, 2022Comments
-
user1937358 almost 2 years
There is a device file called
/dev/console
, whose(major,minor)
is(5,1)
. When I boot with a serial console, it connects to my UART port as/dev/ttyS0
does. But when I boot with serial console disabled, the/dev/console
seems to connect to elsewhere, where/dev/ttyS0
always connects to the same physical device, namelyUART0
. Is there any indication (like something in/proc
or/sys
) showing such information? I have tried there but found nothing I want. I am starting to trace the Linux kernel source to clarify their relationships. Can anyone give me some hints? When, where, how and what to determine the physical device to which/dev/console
connects?EDIT: The latest finding is that:
- the
/dev/console
is configured byconsole=
of the kernel parameters, which in turn is used bygetty
to openstdin/stdout/stderr
. If noconsole=
is specified,/dev/null
is opened asstdin/stdout/stderr
. But I am not sure they are exactly the same with/dev/console
, which implies/dev/console
can have its I/O connecting to different physical devices. - The
/dev/console
can be read if a USB HID keyboard is plugged and theconsole=
is not configured as UART. Therefore/dev/console
==/dev/null
seems to make little sense. Need more investigations.
-
sawdust about 11 yearsTry looking at how the
console=
parameter is handled from the kernel command line. -
user1937358 about 11 yearsYeah, I have looked at that and it turns out the parameters are passed to
init
and in turn togetty_main()
, which is the implementation ofgetty
withinbusybox
. The relevant part is toclose
the original standard input and thenopen
a new one according to the passed parameters. So I am looking for a way which can retrieve the path from a file descriptor; since I want to know what the 'default' device is if noconsole=
specified. -
user1937358 about 11 yearsIt seems that the very fist stdin/stdout/stderr opened by
init
is/dev/null
if no console is specified forgetty
. For those who are interested, it's ininit_main()
->console_init()
->bb_sanitize_stdio()
of the source ofbusybox
. -
John Slegers about 11 yearsDo you have a file
/sys/dev/char/5:1/active
? It should contain the name of the actual device. -
user1937358 about 11 yearsNo, my system doesn't have the file.
-
Raúl Salinas-Monteagudo about 9 yearsDoesn't "tty" give you it?
-
user1937358 about 9 years@esperanto IIRC,
tty
would show /dev/console in the case that HID devices are used.
- the
-
user1937358 about 11 yearsUnfortunately there is no such file on my system, which is an ARM-based embedded device. So far what I have learned is that the console can be configured by
/etc/inittab
. -
agent.smith about 11 yearsInside kernel, whichever is the last module initialized with console= is configured as console. If I understand correctly then inittab is used to configure which tty terminal will be used to run login program.
-
pts over 10 yearsFYI Linux 2.6.35 doesn't have the file, some newer Linux systems have it.
-
CMCDragonkai over 6 yearsOn my desktop linux, this shows
tty0
and then/sys/devices/virtual/tty/tty0/active
showstty7
andtty7
is my X server. -
Dolda2000 over 6 years@CMCDragonkai: I believe that means that
tty7
is the active VC, but that/dev/console
output goes totty0
. -
Dolda2000 over 6 years@CMCDragonkai: How so? It just means that
/dev/console
is set to go to/dev/tty0
(which means the current VC), but it doesn't have to be set up that way. -
CMCDragonkai over 6 yearsCurrently on my system,
/sys/devices/virtual/tty/console/active
says tty0, and/sys/devices/virtual/tty/tty0/active
says tty7. Then this probably means that both are pointing to tty7 in the end.