4

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?

vmemmap
  • 510
  • 4
  • 20
  • 1
    Most probably you have your graphical manager open so it doesn't show the buffer messages. Log in in one of tty (ctrl+alt+F2 for example), for sure you'll see it there, or open a terminal and type `dmesg -wH` or `journalctl -f` to follow the logs. – KamilCuk Sep 28 '20 at 10:21
  • Usually on the console (either "video" (maybe with framebuffer), or serial). It may get in memory so that on next boot, kernel driver and some programs could retrieve it, for further processing. – Giacomo Catenazzi Sep 28 '20 at 12:29
  • @GiacomoCatenazzi, do you mean persistent UEFI memory? Where would it be written after the reboot? – Alex Martian Jan 19 '22 at 13:27
  • @AlexeiMartianov: No, normal RAM. RAM is not reset at reboot, so it is just kernel reserving a small part of ram for the panic, and a program to retrieve it. Nothing unusual for a driver (reserving RAM, also early reservation, in case of memory mapped to IO). – Giacomo Catenazzi Jan 19 '22 at 13:41
  • @GiacomoCatenazzi, maybe hardware specific, which hardware do you have in mind? The question did not mention hardware, only Linux. https://en.wikipedia.org/wiki/Reset_button: "On personal computers,[NB 1] the reset button clears the memory". – Alex Martian Jan 19 '22 at 14:23
  • @AlexeiMartianov: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/kernel_administration_guide/kernel_crash_dump_guide but you are right: it uses special way to restart a new kernel without resetting memory (but I think there were other ways, before virtual machines the kernel testing required acquiring crashes automatically on real hardware) – Giacomo Catenazzi Jan 19 '22 at 15:17
  • @GiacomoCatenazzi, I recall reading somewhere crash dumps can be copied to Non-volatile RAM. The question that way is if normal restart reads it. – Alex Martian Jan 20 '22 at 10:15
  • Found out we can use the "pstore" block oops/panic logger, it writes the panic logs to a block device, so we can easily inspect it after reboot. I believe it's useful. – vmemmap May 09 '23 at 20:29

2 Answers2

2

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.

lvella
  • 12,754
  • 11
  • 54
  • 106
  • Yes, You can execute "sudo systemctl set-default multi-user.target " to disable the desktop and come to the console on the next reboot, so you can see the panic message – ziqi tan Jul 28 '23 at 04:00
0

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.

klutt
  • 30,332
  • 17
  • 55
  • 95