8

I'm trying to diagnose a random reboot on LineageOS 14. last_kmsg is not in /proc, nor it is in /sys/fs/pstore/console-ramoops.

EDIT:

~# mount | grep PSTORE
~# mkdir /mnt/pstore && mount pstore -t pstore /mnt/pstore && ls /mnt/pstore
mount: 'pstore'->'/mnt/pstore': No such device
0

2 Answers 2

12

Back in 2012, /proc/last_kmsg (1) used to be a dump of kernel console messages, exported after reboots by Android's ram_console functionality (CONFIG_ANDROID_RAM_CONSOLE), which used persistent_ram (CONFIG_ANDROID_PERSISTENT_RAM) to handle a block of RAM that wasn't erased across reboots (2).

persistent_ram was based on Linux upstream RAMOOPS code which logged panic and oops messages to RAM. RAMOOPS was deprecated in favor of PSTORE (3) (memory handling) and PSTORE_RAM (4) (logging panics/oops to pstore/dmesg-ramoops). Later PSTORE_CONSOLE support was added (5, 6) to log not only the panics/oops, but all kernel console messages to pstore/console-ramoops-N which can be read later by mounting pstore (7). So the Android specific RAM_CONSOLE (8, 9) and PERSISTENT_RAM (10) were utterly removed.

Now pstore also offers logging userspace messages (PSTORE_PMSG) (11) and other features (12). Plus it supports multiple backends for persistent storage if supported by hardware, though SoC's on Android devices only support RAM storage (ramoops driver, AFAIK).

So it's not possible to enable last_kmsg on an upstream kernel, instead pstore offers a more versatile functionality.

mount: 'pstore'->'/mnt/pstore': No such device

It shows that your kernel isn't built with pstore support. All you need to do is use a kernel built with CONFIG_PSTORE_CONSOLE and optionally CONFIG_PSTORE_RAM (though buggy). Android's init by-default mounts pstore at /sys/fs/pstore (13) from where dmesg-ramoops (on panics/oops only) and console-ramoops can be read.

You can search forums for a custom ROM shipped with such kernel. Or if you have kernel source, you can build yourself on a Linux machine.

NOTE: Some new devices, like Samsung, still expose /proc/last_kmsg interface; I'm not sure whether they use original implementation or pstore at back end.


FURTHER READING: Reading kernel logs

1
  • /sys/fs/pstore/console-ramoops is only accessible if rooted ?
    – Henk Poley
    Jun 26, 2021 at 6:48
0

I did eventually manage to set up some kind of chron job which wrote the log to a file every few seconds. I can't remember how sorry - it was more than two years ago.

The log didn't give me an answer, which I found puzzling. I wondered if the log was not being copied quick enough before the shutdown.

That might be an issue for some people, but I soon discovered the problem was very simple - the battery was faulty. This model (s5) has a removable battery, so I swapped it and the problem was gone. Do the simple things first.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .