I'm trying to figure out at which point in the boot up process /dev/kmsg gets initialized and can thus be written. On my system the first line that occurs in dmesg is printk(KERN_INFO "Initializing cgroup subsys %s\n", ss->name); from kernel/cgroup.c. I tried to trace backwards and search the kernel but I didn't find the function where /dev/kmsg is beeing initialized.

Does somebody know?

1 Answer 1


The /dev/kmsg represeted by the kmsg_fops structure which has file_operations type that represents standard operations with a file:

const struct file_operations kmsg_fops = {
    .open = devkmsg_open,
    .read = devkmsg_read,
    .write_iter = devkmsg_write,
    .llseek = devkmsg_llseek,
    .poll = devkmsg_poll,
    .release = devkmsg_release,

You can find definition of the kmsg_fops and related operations in the printk.c. Its initialization and initialization of other virtual devices as /dev/zero, /dev/null is in the chr_dev_init function.

This function called during Linux kernel initialization process, after the kernel booted and decompressed. Note that after the chr_dev_init function, the:


macro that expands to the __define_initcall macro:

#define fs_initcall(fn)         __define_initcall(fn, 5)

two parameters: function which will initialize char device and initcall level, where 5 is fs:

static char *initcall_level_names[] __initdata = {

The __define_initcall macro expands to the initcall definition which will be called in the do_initcalls from the init/main.c

  • But where is it called during boot process? Can't find it anywhere in /arch/x86 or init? Commented Jul 4, 2015 at 17:50
  • I've update my answer, and I think that it is enough :)
    – 0xAX
    Commented Jul 4, 2015 at 18:05
  • Okay now I understand why I didn't find it. Thanks a lot! Commented Jul 4, 2015 at 18:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .