2

My phone keeps rebooting. I want to know what dmesg says at the moment it reboots, so I can diagnose.

Unfortunately, the reboots don't happen predictably, and only when I'm using it. I can't keep my phone connected to my laptop for days on end. I have it connected via adb right now, and of course the little varlet isn't rebooting. There is no last_kmsg, either.

The version is LineageOS 14. I'm posting here because the answer to this question would presumably apply to all unix-based systems. If you don't like, I suppose punt it over to Android.

What I'm envisioning is it writing to the log constantly until it reboots. I realise that if the phone doesn't reboot itself, the log will eventually fill up the SD card. So I'm picturing a script like:

dmesg to log.1
if log.1 >1mb, delete it 
dmesg log.2
if log.2 >1mb, delete it 
dmesg to log.1

I don't have the skills to write it though. Can anyone help?

2

If you have the wherewithall to run a bash script this will maintain a file counter and use it to create an circular sequence of dmesg log files.

#!/bin/bash
dir=/path/to/storage                             # Location of persistent storage

[[ -z "$dir/count" ]] && echo 0 >"$dir/count"    # Seed the counter if missing

while sleep 0.25
do
    count=$(( $(cat "$dir/count") +1 ))          # Read the counter and increment
    [[ $count -gt 600 ]] && count=1              # Reset so we can reuse diskspace

    echo $count >"$dir/count"                    # Save the new value
    dmesg >"$dir/dmesg.$count"                   # Write the data
done

You will need to review the resulting set of up to 600 log files in date-modified order (ls -t) because they will be written and rewritten like a circular buffer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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