Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to write some custom messages in my dmesg output. I tried:

logger "Hello"

but this does not work. It exits without error, but no "Hello" appears int the output of:


I am using a Fedora 9, and it seems that there is no syslogd/klogd daemon running. However, all my kernel messages are succesfully written in the dmesg buffer.

Any idea?

share|improve this question

4 Answers 4

up vote 22 down vote accepted

dmesg displays what is in the kernel buffer, whereas logger is for syslogd. I think if you want to print things into the kernel buffer you will need to create a driver that uses the printk() kernel function. If you just want it in /var/log/messages, then with a "normal" setup I think what you have done with logger is already fine.

The most basic example of a driver with printk() would be:


#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void)
    printk(KERN_INFO "Hello world\n");
    return 0;

void cleanup_module(void)
    printk(KERN_INFO "Goodbye world\n");



obj-m += hello.o

    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules


$ make
$ sudo insmod hello.ko
$ dmesg | tail -n1
 [7089996.746366] Hello world for more...

share|improve this answer
I got an error, since you have put spaces before the make -C ... in the Makefile instead of a Tab, so copying the above contents of the Makefile does not work - more here. I appear to be unable to add this in an edit... Thanks by the way, great answer. – Wilf Jul 11 '14 at 18:17

You can, as root, write to /dev/kmsg to print to the kernel message buffer:

 fixnum:~# echo Some message > /dev/kmsg
 fixnum:~# dmesg | tail -n1
 [28078118.692242] Some message

I've tested this on my server and an embedded Linux device, and it works on both, so I'm just going to assume it works pretty much everywhere.

share|improve this answer
Interesting that in Ubuntu, this works as root but not with sudo. One actually needs to become root. – dotancohen Jun 30 '12 at 8:53
Actually, that's because the input redirection is handled by your shell, which is not running with elevated rights. Try running echo Some message | sudo tee /dev/kmesg as non-root. – wvdschel Jul 4 '12 at 11:56
That works. Thanks, interesting. By the way, its kmsg not kmesg but I also confuse with dmesg which has the e! – dotancohen Jul 4 '12 at 14:55
Much easier than compiling kernel module – e271p314 Mar 3 '14 at 9:22

Based on Kyle's module above:

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>

static int pk_write(struct file *file, const char *buffer, unsigned long count, void *data)
        char string[256];
        count = count < 255 ? count : 255;

        if(copy_from_user(string, buffer, count))
                return -EFAULT;

        string[count] = '\0';        
        return count;

static int __init printk_init(void)
        struct proc_dir_entry *pk_file;

        pk_file = create_proc_entry("printk", 0222, NULL);
        if(pk_file == NULL)
                return -ENOMEM;

        pk_file->write_proc = pk_write;
        pk_file->owner = THIS_MODULE;

        return 0;

static void __exit printk_cleanup(void)
        remove_proc_entry("printk", NULL);


To do a printk from user space:

echo "Hello" > /proc/printk
share|improve this answer

Based off of Kyle's answer, here is a quick tutorial showing how to do just that.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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