Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 937
user1937358 Avatar asked Mar 19 '13 06:03

user1937358


People also ask

Which device name represents the terminal connected to the current process?

According to the POSIX standard, /dev/tty is considered to be the terminal associated with a process group whereas /dev/tty0 is associated with a virtual terminal.

What is tty0 in Linux?

tty0 is just an alias for the current virtual terminal and it's where messages from the system are sent. Thus messages from the system will be seen on the console (monitor) regardless of which virtual terminal it is displaying.

What is console ttyS0?

The console is the tty where the kernel logs go to. You select a specific one through kernel parameters when booting, it is seen in the log you provided, in the line "Kernel command line: console=ttyS0,115200 root=/dev/mmcblk0p2 roo twait loglevel=8 panic=10"

How do I access a device on Linux?

First, you need the partition ID ( /dev/sdXY ). You can use the lsblk command to find this. Once you have this ID, you can run sudo mount /dev/sdXY /mnt . Your flash drive's filesystem will now be available at /mnt and can be used from the terminal.


1 Answers

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

like image 156
Dolda2000 Avatar answered Oct 19 '22 03:10

Dolda2000