8

My OS Ubuntu 12.04. I wrote this Kernel Module and i use insmod and rmmod command but there isn't anything in /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");
 }
amiref
  • 3,181
  • 7
  • 38
  • 62

5 Answers5

1

Check whether syslog daemon process is running, since this is the process which copies printk messages from kernel ring/log message buffer to /var/log/messages if I am correct. printk messages can be seen using dmesg utility/command or messages will be in /var/log/messages. If correct loglevel is set then printk messages will be displayed on the console right away, no need to use dmesg or no need to check in /var/log/messages. printk debug messages can also be part of /var/log/syslog.

Gautham Kantharaju
  • 1,735
  • 1
  • 21
  • 24
0

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

0

Firstly, you should check that whether your module is properly loaded or not, by using this command

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

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

dmesg | grep "Hello World 1." 
Zzz0_o
  • 590
  • 7
  • 14
0

Look for this in /etc/syslog.conf, the *.info... lines. These seem to control what gets logged via printk.

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

I found that /proc/sys/kernel/printk only really controlled the console logging levels, not the logging to the file. And I guess check syslog is running too ;) We had exactly the same issue, KERN_INFO not going to log files and this fixed it. hth

Goblinhack
  • 2,859
  • 1
  • 26
  • 26
0

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

Shivam Papat
  • 457
  • 4
  • 14