0

I am trying to understand the console= parameter provided to the kernel and doing so I have modified /etc/default/grub to set console up to be tty3 such as (the reason I have chosen tty3 as opposed to ttyS0 is that I don't have a serial port): enter image description here

I am assuming by setting up console to be tty3 the kernel will only output messages to tty3 and no other tty. I have entered using Ctrl+Alt+F2 into tty2 and pressed the key Alt+SysRq+H. If I check dmesg I can see the message there.

By doing that I can see the message of the kernel in the current tty2. By navigating to tty3 I do not see any messages.

Just for completeness, console is configured correctly to point to tty3:

~$ cat /sys/devices/virtual/tty/console/active
tty3

Furthermore to this, I have compiled a generic helloworld module and performed insmod and rmmod on it. The output appears on the currently active tty and not the specified console (tty3).

I don't understand why this is happening. Could someone explain? Have I misunderstood the console parameter?

  • 1
    I suspect this is because tty3 doesn't exist at early boot time, and I mean "exist" as an allocated data structure inside the kernel, not as a node under /dev/. The ttyN devices (where N>1) are allocated on demand from userspace, I think - and at that time there is no userspace. Anyway, I also like to see messages on a VT, but I do that with syslog (/etc/rsyslog.conf since I use mostly Debian and derivatives). Also see the sysctl setting kernel.printk for a way to regulate console noise. – q.undertow Jun 14 at 18:53
2

The names that are used in the console= setting of the Linux command line are not device filenames that are looked up in the filesystem. They are actually a combination of a registration name and an index, "tty3" being the registration name "tty" and the index 3.

The registration names are compared against the internal names that device drivers use to register console I/O handlers. These need not match user-space device names at all. "tty" matches the name used by the kernel virtual terminal subsystem when it registers its console I/O handler.

The index is not the KVT number. It is used for matching a particular console I/O handler instance when a device driver provides more than 1 console I/O handler by the same name. This is not the case for the KVT subsystem, which only registers one console I/O handler. In such a case, the index is in fact largely ignored. And this is indeed what happens with the index 3.

Yes, the Linux doco says otherwise. The Linux doco is wrong. Again.

Furthermore, the KVT subsystem by default writes all console output, when it has been selected as a console in the first place, to the currently active KVT. This can be changed, but not by the registration index numbers used on the kernel command line in console= specifications. Rather, it is changed by issuing a TIOCL_SETKMSGREDIRECT subcommand to the TIOCLINUX ioctl() against a KVT device (for best results, the KVT device that is being redirected to, otherwise the KVT may not even exist, as KVTs are not created until their device files are opened).

The Linux doco doesn't get this wrong. It rather simply doesn't document TIOCL_SETKMSGREDIRECT at all on the console_ioctl manual page.

For non-programmers, this functionality is accessible via tools such as the rather misleadingly documented Busybox setlogcons command and Allan Cruse's setconsole.

Further reading

  • Jonathan de Boyne Pollard (2018). "linux-vt". Devices. nosh toolset.
  • Jonathan de Boyne Pollard (2018). "linux-console". Devices. nosh toolset.
| improve this answer | |
  • One thing to add which is confusing as well is that if I do console=tty3 and then I do "init 1" (go to single user mode) tty3 is indeed the active tty. This is where the logging prompt is located. Seems like a separate mechanism and convention is used to the kernel itself. – Har Jun 14 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.