Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to get kernel logs after kernel panic?

Tags:

I am using an Android Custom ROM on my device, also with a custom boot.img (custom kernel + cmdline + ramdisk). I now want to be able to view the kernel logs immediately after a kernel panic, but unfortunately I can not use a serial console.

The good news: There seem to be some sources/modules in the Linux kernel of Android that are written exactly for this purpose. For example, the following lines are activated in my .config file for the kernel:

CONFIG_ANDROID_RAM_CONSOLE=y CONFIG_ANDROID_RAM_CONSOLE_ENABLE_VERBOSE=y CONFIG_APANIC=y CONFIG_APANIC_PLABEL="oem_log" 

My problem is: After I forced a kernel panic in order to test this, i.e. by loading a simple panic kernel module with insmod panic.ko, it seems that no log was written to the MTD named oem_log (which exists on my device). Secondly, the RAM also does not contain logs after reboot because it seems to be cleared - or the logs are not written either.

So how can I get the kernel logs after a panic? Also it would be helpful if there is a way I could test the APANIC on the running system. Maybe by using the kernel debug system? As of now I am pretty new to this.

Thanks in advance for any help!

like image 925
mreichelt Avatar asked Mar 13 '12 10:03

mreichelt


People also ask

How do I access kernel logs?

You can also view this log using the dmesg command. Another log you can use to view kernel information is the /var/log/kern. log file, this logs the kernel information and events on your system, it also logs dmesg output.

What happens after kernel panic?

If your Mac restarts unexpectedly, an error known as a kernel panic occurred, and a message indicates that your computer restarted because of a problem. The most likely cause is faulty software.

Where are the kernel crash logs?

Kernel log messages can be viewed in /var/log/dmesg files even after restart of the system. There will be so many files with dmesg. X, and those files are previous kernel logs. dmesg is the latest file.


2 Answers

As for me,

cat /proc/last_kmsg  

after reboot (caused by the kernel panic during insmod) does list messages relevant to the crash, like

[  424.909515] Kernel panic - not syncing: Fatal exception [  424.909606] Backtrace:  [  424.909790] [<c005a5ec>] (dump_backtrace+0x0/0x10c) from [<c05f38dc>] (dump_stack+0x18/0x1c) [  424.909973]  r6:c5cccf00 r5:00000000 r4:c08505a0 r3:00000000 

So you can at least try. I am working with Linux 3.0.31-g4f6d371 on Galaxy Nexus.

like image 122
Audrius Meškauskas Avatar answered Oct 13 '22 20:10

Audrius Meškauskas


It seems at Android-7.0 or above, the last_kmesg log is moved to: /sys/fs/pstore/console-ramoops, so try:

cat /sys/fs/pstore/console-ramoops 

it works well for me on nexus-5x

like image 42
zhiqiu Avatar answered Oct 13 '22 21:10

zhiqiu