user1937358
user1937358

Reputation: 249

How can I find which physical device /dev/console connects to?

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, namely UART0. 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:

  1. the /dev/console is configured by console= of the kernel parameters, which in turn is used by getty to open stdin/stdout/stderr. If no console= is specified, /dev/null is opened as stdin/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.
  2. The /dev/console can be read if a USB HID keyboard is plugged and the console= is not configured as UART. Therefore /dev/console == /dev/null seems to make little sense. Need more investigations.

Upvotes: 16

Views: 14464

Answers (2)

lamiaani
lamiaani

Reputation: 11

From http://man7.org/linux/man-pages/man4/console.4.html : "The current console is also addressed by /dev/console or /dev/tty0, the character device with major number 4 and minor number 0."

I hope that was what you were looking for.

Upvotes: 1

Dolda2000
Dolda2000

Reputation: 25855

I think /sys/devices/virtual/tty/console/active is what you're looking for.

Upvotes: 10

Related Questions