12

I know that the boot up log can be obtained by pulling out contents of kmsg or dmesg through ADB.
But I'm not aware of how to retrieve the shutdown logs in Android as there's no /var folder in Android (place where most desktop linux distros generally store their shutdown logs).

So how can I obtain the shutdown logs in Android?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125

6 Answers6

12

Look in some locations such as these:

/proc/last_kmsg
/data/tombstones/
/data/dontpanic/
/data/system/dropbox/

(This list isn't strictly kernel logs, including framework and application logs too, which are also sometimes of interest)

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • Thanks for the reply Chris! I checked for the locations on my phone. I couldn't find /proc/last_kmsg and /data/tombstones/. And an "ls" on /data/dontpanic returned nothing!! I had some luck in /data/system/dropbox/ as they contained files like SYSTEM_BOOT@915149630014.txt system_app_strictmode@915149633098.txt.gz They are having some APP level info. None of them had the info that we get from kmsg :( – Pavan Manjunath May 24 '11 at 10:48
  • 1
    You don't have files like SYSTEM_LAST_KMSG@xxx.txt.gz in /data/system/dropbox? It may be that isn't a standard feature... unfortunately. – Chris Stratton May 24 '11 at 14:33
  • No Chris! There aren't any such *LAST_KMSG* kind of files!! Anyways thanks a lot for your help! Do reply back if you find any other clues, I am still behind the shutdown logs in android!! – Pavan Manjunath May 25 '11 at 11:29
4

TL;DR:
Run command through adb that copies logcat and proc/kmsg to a file and keep it running even when adb disconnects with nohup, disown or setsid. Probably needs busybox, needs root and adb root, too.
setsid cat proc/kmsg > /sdcard/kmsg.txt &
and
logcat -v long -f /sdcard/logcat.txt (somehow only works without setsid)

Or add normal copy commands to some startup script.
/TL;DR

You can constantly copy proc/kmsg and logcat to a file on your android device or a microSD card to get the logs even after adb disconnects.

You need root access and adb root access for this to work. For the latter, use the setting in the developer options if you have a custom rom or the adbd insecure app.

After using adb shell to get your android shell, type su to get superuser access.

Then you not only need to put an ampersand (&) after the command but also make sure that the command keeps running after adb disconnects. That is done by nohup, disown or setsid (see here for usage).
If it doesn't work because you don't have these commands, you need to install busybox.
See my question here.

See here for how to get logcat and kernel logs and print it to some file or merge it. See developer.android.com/tools/help/logcat.html for parameters for the logcat command.

In the end you could have a command like setsid cat proc/kmsg > /sdcard/kmsg.txt & for the kernel messages.

For logcat you could have one of the following commands: logcat -v long -f /sdcard/logcat.txt or logcat -v long > /sdcard/logcat.txt

I don't know why, but sometimes it didn't work with setsid and just didn't copy continuously but stopped shortly after executing the command. In these situations, it also showed up when entering jobs, which it didn't otherwise. Then it just worked without setsid, it stayed alive after disconnecting and reconnecting. I guess you must just try when the file does keep getting larger. If someone figured out why it is behaving like it is... let me know and I'll edit the answer.

Probably adding the commands to a startup script could be a solution for some, too.

Hope this helps.

fightcookie

Community
  • 1
  • 1
xuiqzy
  • 179
  • 2
  • 14
3

Newer phones do NOT use any of these locations so if you're reading this article then as of now

The kernel crash logs are now in /sys/fs/pstore instead of /proc/last_kmsg

aryanisno1
  • 71
  • 3
3

One work around I found for collecting shutdown logs in Android is to run adb pull /proc/kmsg C:\Logs.txt on the host PC and then switch off the device. You will get the logs till the USB communication between the host and the device snaps! I know this is only one case out of the numerous shutdown scenarios but I haven't found satisfactory answers for other cases!

Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125
  • Unfortunately you just don't know when your damn phone is going to shut down on its own like my phone is doing. It thinks 35% of battery is too low and so shuts itself down even after restarting it. Sometimes it doesn't until it reaches 10%. God damn Android – TheRealChx101 May 14 '17 at 13:04
1

getprop also has sys.boot.reason.last which has basic details for the last reboot of an Android device:

adb shell getprop | grep -A3 boot.reason 
[persist.sys.boot.reason]: []
[persist.sys.boot.reason.history]: [watchdog,1692290965
reboot,userrequested,1692249163
watchdog,1691516754
watchdog,1691078769]
--
[sys.boot.reason]: [watchdog]
[sys.boot.reason.last]: [watchdog]
[sys.boot_completed]: [1]
[sys.bootstat.first_boot_completed]: [1]
[sys.fuse.transcode_enabled]: [true]

Greg Bray
  • 14,929
  • 12
  • 80
  • 104
0

I was looking for the same thing, and finally, I found the answer!

In android 8 all logs are located in \data\log\android_logs\... including apps and kernel logs. Kernel logs are called kmsgcat-log_timestamp_.gz

edit: Although this is a very old thread, I think the answer might be helpful.

Nima
  • 404
  • 3
  • 14