2

I'm trying to find/figure out if a computer using Ubuntu 16 had an unexpected power down.

I checked many sources on Internet, review the logs in the /var/log files, but I could not find any clear indication about this kind of events.

I'm running Ubuntu VMs under either Windows Hyper-V and Virtualbox. As a matter of testing, I can power off the VM and I expect to be able to find this event in the logs, similar that I can do with the Windows Logs.

I know that I can write my own way writing a file in a script at the shutdown time and looking for this file at the boot time, but considering the maturity of Linux/Ubuntu, I think should be something already, and trying to reinvent the wheel.

Thanks for any help.

  • Look here: http://askubuntu.com/q/58625/295286 Proper shutdown means unmounting of the / filesystem (usually /dev/sda1 ) , so if you don't find that line, it probably wasn't a proper shutdown. – Sergiy Kolodyazhnyy Jun 28 '16 at 21:26

2 Answers2

1

Try this:

nice sudo zgrep "recovery complete" /var/log/kern.log*

Output example for Proxmox 5 (Debian 9 stretch, Linux 4.15.18):

/var/log/kern.log:Apr 21 18:56:16 pve kernel: [   83.475918] EXT4-fs (dm-8): recovery complete
/var/log/kern.log.1:Apr 18 18:01:39 pve kernel: [   89.627622] EXT4-fs (dm-8): recovery complete
/var/log/kern.log.3.gz:Apr  5 19:00:09 pve kernel: [   83.572224] EXT4-fs (dm-8): recovery complete

Yes, here is bad situation, because of often unexpected shutdowns, so I have to replace battery in my UPS.

1

Look at the file /var/log/kern.log*, and find the most recent

Jun 28 10:16:08 aardvark kernel: [    0.000000] Initializing cgroup subsys cpu 
#   Time/date   hostname  who    usec since boot

That's the first thing that gets logged when the system comes up. The lines of /var/log/kern.log* just before that line are the last events logged before the system went down. If there are no errors or warnings above the [ 0.000000] line, or if there is a large interval of time between last pre-crash event and the first boot line, suspect power. It takes some form of UPS or battery backup to be able to log "Power is off".

waltinator
  • 36,399