Where does the linux kernel panic message go?

Viewed 701

I don't know if it's related to SO. I know that when I use the Linux kernel panic function, its job is to freeze my system, but it takes 1 argument, a message. Where can I actually see the message if my system is completely frozen and I force shutdown my PC by holding the power-off button?

main.c

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

MODULE_LICENSE("GPL");

static int __init initialization_function(void)
{
    panic("Module: my message!\n");
    return 0;
}

static void __exit cleanup_funcion(void)
{    
    printk(KERN_INFO "Module: Cleanup done, exiting.\n");
}

module_init(initialization_function);
module_exit(cleanup_funcion);

By the way, I don't know how can I see the actual oops message, where and how can I see it?

2 Answers

It goes to the kernel console, the same place where printk() message goes. There is a screenshot in Wikipedia article on kernel panic:

enter image description here

Usually, you will be able to see it if the kernel panic happens at boot time.

As for what happens if you have a running desktop system, unfortunately I don't remember. Either you won't see it, or X/Wayland server will crash and you will see the message it in the console.

As you have noticed yourself, this is pretty tricky since the system gets frozen. What you can do is to have a look in the system log after reboot. Exactly how that is done depends on the distribution. On a system with systemd you can use journalctl -xe.

Related