I am trying to teach myself Linux kernel development by working through Linux Device Drivers, and I'm currently on the chapter about debugging. From everything I've read, printk() messages are supposed to go to "the console", which from what I understand, is usually represented by the device "/dev/console".
The problem is that I can not get any of my pritnk statements to appear when I monitor /dev/console using the xconsole utility. My messages DO appear in the system logs, and I can see my messages when I use dmesg. So I am not asking about this for practical purposes, but rather to fill in my own gaps in understanding the Linux system.
I set my printk messages to the highest log level (KERNEL_EMERG), just to be sure they weren't getting filtered. I used dmesg -E
which supposedly "enables console logging", but nothing worked.
I am running Kubuntu 20, with custom kernel 5.4.55. with the kernel debugging config option enabled. Here is my /proc/cmdline file:
BOOT_IMAGE=/boot/vmlinuz-5.4.55 root=UUID=3978ed71-51b0-4505-83b9-58401946ed0f ro console=tty0 vt.handoff=7
Here is my /proc/sys/kernel/printk :
4 4 1 7
And here is my kernel configurations:
Thank you for your help
Edit
To addition to @user433151's answer, I found that printk() messages only appear on the currently active virtual terminal, even when the console is explicitly set during boot. For example, booting with console=tty2
only seems to effect the fact that /dev/console "points" to tty2, it does not make tty2 the "target" console for kernel messages. It appears the default "target" console for kernel messages is always tty0, so in order for printk messages to appear on tty2, tty2 must the be the currently active virtual terminal at the time the printk message is written. Part of my confusion came from running my modules on tty1, then switching to tty2 only to find my printk statements not appearing. My solution was to start the modules in tty2, or to redirect messages with ioctl(TIOCL_SETKMSGREDIRECT)