32

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!

5 Answers 5

34

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.

4
  • I am marking this as the correct answer - but it only seems to work if this functionality was implemented correctly for the particular device. Which, for me (at the time I asked the question and for my particular device) was not the case.
    – mreichelt
    Oct 24, 2014 at 13:47
  • 2
    Does this file exist is the device hasn't panicked
    – Suici Doga
    Feb 21, 2016 at 5:35
  • 1
    Doesn't exist, kernel version 3.0.8+.
    – ogurets
    Feb 12, 2017 at 11:55
  • https://android.stackexchange.com/questions/239500/analyzing-boot-loop-root-cause-from-console-ramoops-0-logcat this question carrying a bounty might be of intrest if you are that 'colonel' of kernel Jul 29, 2021 at 5:28
22

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

3
  • 8
    For me, it was cat /sys/fs/pstore/console-ramoops-0.
    – nyanpasu64
    Oct 13, 2018 at 2:34
  • Yes, it may add id as suffix.
    – zhiqiu
    Sep 26, 2019 at 9:08
  • this would work if you are a root user, what would generally mean you will have to root your device. On Samsung, once you burn the fuse, you are no longer able to install standard OS.
    – Hrvoje
    May 31 at 14:09
10

How about /data/dontpanic folder? After kernel panic happens, you can connect USB cable with your Android device and check the files in that folder through ADB.

I found this folder contains some apanic files after a kernel panic happens. For example, if a kernel panic just happened and you go check the folder, you might find these two files:

apanic_console

apanic_threads

You can find out in apanic_threads which thread / process is running when the kernel panic happens. In apanic_console you might find out more information such as the stack trace and values of some critical registers: PC, LR, etc.
They will help you get your debugging started.

2
  • 1
    I have this folder, but no files inside (after the panic). Executed 'find / -name "panic"' and found something interesting: "/sys/module/kernel/parameters/panic" and "/proc/sys/kernel/panic", both containing "2" on my device.
    – ogurets
    Feb 12, 2017 at 11:59
  • Excellent tip. Thx!
    – imbr
    Feb 28, 2021 at 16:44
3

Android creates a RAM console and attempts to save the last kernel message buffer for you in RAM (assuming the power doesn't go out). You can access this file through the proc interface and on my system it is world readable:

cat /proc/last_kmsg

For more information see the kernel code @ drivers/staging/android/ram_console.c

1
  • Path does not exist for modern Android versions (tested with 13, path missing). Feb 7 at 7:59
1

I faced a similar issue of collecting shutdown logs in Android. I had posted this question long back and it has 2 approaches. I use the 2nd one as the 1st one doesn't work for me. Here is the question

Where does Android store shutdown logs?

Hope this helps.

4
  • Unfortunately, all the files described there are only available if the APANIC module works correctly - which is what I am trying to achieve...
    – mreichelt
    Mar 20, 2012 at 16:02
  • @mreichelt No luck with connecting to adb and trying to pull kmsg? Mar 20, 2012 at 16:08
  • kmsg is the current log. I want to get the kernel logs after a kernel panic occured, i.e. when the system crashed and the device is rebooted. That is what APANIC is for.
    – mreichelt
    Mar 21, 2012 at 16:43
  • If you want to figure out what caused a kernel panic, then I think the kernel logs leading to the panic should be of interest to you. Irrespective of whether before or after, AFAIR kernel logs are always in kmsg Mar 21, 2012 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.