Another method is to store the kernel log messages and kernel panics or oops into persistent storage. The Linux kernel's persistent store support (CONFIG_PSTORE) allows you to log in to the persistent memory kept across reboots.
To log panic and oops messages into persistent memory, we need to configure the kernel with the CONFIG_PSTORE_RAM configuration variable, and to log kernel messages, we need to configure the kernel with CONFIG_PSTORE_CONSOLE.
We then need to configure the location of the persistent storage on an unused memory location, but keep the last 1 MB of memory free:
- For example, we could pass the following kernel command-line arguments to reserve a 128 KB region starting at 0x30000000:
ramoops.mem_address=0x30000000 ramoops.mem_size=0x200000
- We would then mount the persistent storage by adding it to /etc/fstab so that it is available on the next boot as well:
/etc/fstab: pstore /pstore pstore defaults 0 0
- We then mount it as follows:
# mkdir /pstore # mount /pstore
- Next, we force a reboot with the magic SysRq key:
# echo b > /proc/sysrq-trigger
- On reboot, we will see a file inside /pstore:
-r--r--r-- 1 root root 4084 Sep 16 16:24 console-ramoops
- This will have contents such as the following:
SysRq : Resetting CPU3: stopping CPU: 3 PID: 0 Comm: swapper/3 Not tainted 3.14.0-rc4-1.0.0-wandboard-37774-g1eae [<80014a30>] (unwind_backtrace) from [<800116cc>] (show_stack+0x10/0x14) [<800116cc>] (show_stack) from [<806091f4>] (dump_stack+0x7c/0xbc) [<806091f4>] (dump_stack) from [<80013990>] (handle_IPI+0x144/0x158) [<80013990>] (handle_IPI) from [<800085c4>] (gic_handle_irq+0x58/0x5c) [<800085c4>] (gic_handle_irq) from [<80012200>] (__irq_svc+0x40/0x70) Exception stack(0xee4c1f50 to 0xee4c1f98)
- We should move it out of /pstore or remove it completely so that it doesn't occupy memory.