Printk () does not print in / var / log / messages

My OS is Ubuntu 12.04. I wrote this kernel module and I use the insmod and rmmod command, but there is nothing in the / var / log messages. How can I fix this problem?

/* * hello-1.c - The simplest kernel module. */ #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ int init_module(void) { printk(KERN_INFO "Hello world 1.\n"); /* * A non 0 return means init_module failed; module can't be loaded. */ return 0; } void cleanup_module(void) { printk(KERN_INFO "Goodbye world 1.\n"); } 
+8
linux linux-kernel kernel kernel-module
source share
5 answers

Check if the syslog demo process is running, as it is a process that copies printk messages from the kernel message / message log buffer to / var / log / messages if I am True. Printk messages can be seen using the dmesg utility, or the messages will be in / var / log / messages. If the correct log level is set, then printk messages will be displayed on the console immediately, there is no need to use dmesg or there is no need to check / var / log / messages. Printk debugging messages can also be part of / var / log / syslog .

+1
source share

Modern Linux distributions no longer use rsyslog (or any other syslog daemon). They rely on journald, which is part of systemd, so the / var / log / messages file is missing, and you should use the journalctl command to read the system log.

0
source share

First, you must check if your module is loaded correctly or not using this command

 lsmod | grep "hello-1" //hello-1 is the name of your module 

Since you wrote a kernel module that prints some kind of message. Messages from the kernel and its module can be found in / var / log / syslog, or you can view these messages using the dmesg command. When your module prints "Hello World 1.", you should use the following command to view the message from your module.

 dmesg | grep "Hello World 1." 
0
source share

Look for this in /etc/syslog.conf, * .info lines .... It seems that they control what is logged through printk.

 *.=info;*.=notice;*.=warn;\ auth,authpriv.none;\ cron,daemon.none;\ mail,news.none -/var/log/messages 

I found that / proc / sys / kernel / printk actually controls the console logging levels, not logging to a file. And I think the syslog check is also running;) We had exactly the same problem, KERN_INFO was not going to write files, and this fixed it. Hth

0
source share

I tried to print the kernel buffer by typing the following command: dmesg
This will print the data written in printk

0
source share

All Articles