Shutdown logs in linux

How can I log shutdown console text? [duplicate]

In Oneiric shutdown is a lot slower than in previous releases and when I look at the console text while shutting down there seems to be a problem with the network manager. Now I wanted to know how I log the text being shown during shutdown.

3 Answers 3

Shutdown (and boot) messages are logged in /var/log/syslog .

as of Ubunutu 16.04 this seems no longer correct. i.e. I don’t get cat /var/log/syslog | grep -i «stopped target user» (and similar. also sanity-tested the contrary), despite that this was part of the previous shutdown. (visible, when pressing ESC to kill the splash screen while shutting down)

Ubuntu doesn’t record the shutdown message log anywhere and there’s no way to force it to, at least not on my install of Oneiric, not the messages you see scrolling by during shutdown as you frantically reach for your cellphone camera to snap a pic of the dreaded «[fail]» message before it’s gone.

I also expect Ubuntu 11.10 to be slower because of network-manager. While shutting down it seems to time out and end with the message

«nm-dispatcher.action: Caught signal 15, shutting down. . «

I have removed the network-manager and configured my ip address by using /etc/network/interfaces and it is now fast again.

I replaced Network-Manager with Wicd, downloaded some nicer icons from gnome-look and my computer shuts down in an appropriate time. But I wanted to file a bug on Launchpad with the shutdown text to get Network-Manger back as it’s nice than Wicd.

Источник

How to read the shut down messages afterwards?

I’m using Lubuntu 11.10. Every time I shut down I can read FAIL in red letters, but I can not read more. So, how to read the log messages and try to solve the problem?

everything recored at /var/log/syslog and /var/log/messages , So you need to read them and throubleshoot. You can use io redirection with error redirection when you use shutdown command

9 Answers 9

There seems to be no way to log this data to a file. For the boot process, there is the bootlogd package which creates the file /var/log/boot , but nothing for the shutdown/reboot process. As far as I can see there is no way to log with rsyslog either, and even if there was, there are messages printed after rsyslog is stopped. Part of my shutdown/reboot process is to remount the rootfs readonly and umount everything else, after this logging to a file that will still be there at the next boot is virtually impossible.

The easiest way I can see to view the messages is to edit the /etc/init.d/halt and/or /etc/init.d/reboot scripts to pause just before the actual halt / reboot . For the halt script, run the command sudoedit /etc/init.d/halt (or use a GUI editor) and look for the line that does the actual halt. For me this is the line:

halt -d -f $netdown $poweroff $hddown 

Otherwise it should be at the end of the do_stop function and the only line that calls the halt command. Once you find the line, just insert a new line above with the following:

read -p "Press enter to halt" reply 

Save the file and exit. Now when you shutdown, the system will pause until you press enter (or CTRL-C, CTRL-D, etc). You can the read the messages printed on the screen. If there is more than a single screenful of text, you can see terminal scrollback by pressing Shift+PgUp . If this is still not enough, there are ways to increase the size of the scrollback buffer (perhaps a different question though).

Читайте также:  Просмотр все открытых портов linux

To do the same when the system reboots, you have to edit the /etc/init.d/reboot file. The command used here is of course reboot as opposed to halt and should again be at the end of the do_stop function. For me the line is:

Again just insert the following on a new line above:

read -p "Press enter to reboot" reply 

Note also that these files are listed as conffiles for the initscripts package. These edits won’t be clobbered by default when the packages is upgraded, although they will cause a conflict.

A more complete solution would be to use the following script:

#! /bin/sh ### BEGIN INIT INFO # Provides: pause_hook # Required-Start: # Required-Stop: halt reboot # Default-Start: # Default-Stop: 0 6 # X-Stop-After: umountroot # X-Interactive: true # Short-Description: Pause before halt or reboot # Description: ### END INIT INFO do_stop () < [ -r /etc/pause_hook.conf ] && . /etc/pause_hook.conf [ "$PAUSE_HOOK_ENABLED" = true ] && read -p "Press enter to continue" reply >case "$1" in start) # No-op ;; restart|reload|force-reload) echo "Error: argument '$1' not supported" >&2 exit 3 ;; stop) do_stop ;; *) echo "Usage: $0 start|stop" >&2 exit 3 ;; esac 

This should be placed in /etc/init.d/pause_hook and can be enabled to run at shutdown/reboot with the following command:

sudo update-rc.d pause_hook defaults 

To then enable the actual hook, create the files /etc/pause_hook.conf containing the line:

The shutdown/reboot process should now pause just before the halt or reboot script is called, giving time to view the messages. It can also be easily disabled/re-enabled by commenting/uncommmenting the enable line in /etc/pause_hook.conf . There will also be no dpkg conffile conflicts during upgrades this way.

Easiest solution might be to try taking a video instead of a photograph. You can step through it frame-by-frame later.

Some of those messages are printed after filesystems are unmounted! So they can’t all end up in a file.

Seeing the log in real time

I’ve found that during shutdown there is usually an Ubuntu logo and flashing lights, which is shown instead of a log of the shutdown process. If there are errors, then they’re kind of shown, but messily. However, whilst shutting down, if I press the Windows key and r ( Meta r ), then I get to see the success and failure of the system services, as they occur. So then I know what exactly is broken. No idea whether this keyboard shortcut is specific to my Kubuntu setup or what; I didn’t add it.. One of those I found by accident, somehow.

Читайте также:  Посмотреть арп таблицу linux

Viewing the logs after rebooting

When the system is rebooted, the error messages should be saved into a logfile. Which logfile depends on which service is broken/misconfigured. The relevant log will almost definitely be in /var/log/ (or a subdirectory thereof). ls , less , grep and find have been the only programs I’ve needed for finding error messages in the logs.

Once you’ve found the error and the service that caused it, then you shouldn’t need to reboot to test the new configuration; just restart the service.. Hopefully you can test the fixed configuration with a command like:

Is it Windows+r or Alt+r you are pressing? Default mappings map the windows key to super and the meta key to alt so it is unclear exactly which key you are describing.

After looking into how bootlogd actually manages to do the logging, it turns out that it can be persuaded to log the shutdown/reboot process as well as the startup one. bootlogd is started early in the boot process. It then does some magic with tty and pts devices to log all output to the terminal it is connected to. It is then stopped later in the boot process, presumably before it would start logging the output from a user working on the tty .

If bootlogd is fired up again during the shutdown/reboot process and stopped before whichever file system containing the log is unmounted, there will be a record of most of the shutdown process available to read at the next boot.

bootlogd manages to be both started and stopped during the startup by having two init scripts. One is a normal init script which is starts/stops the process as normal. The other is a ‘reversed’ init script in that when called with start , it calls the first script with stop. This ‘tricks’ the sysvinit process, it appears that it is starting two separate services when it is really starting and stopping the same service. This is needed to make sure everything happens in the right order.

To make bootlogd run during shutdown, what is required is:

  1. Install bootlogd if you haven’t already.
  2. Copy the two init scripts
  3. Make the ‘reversed’ script change stop to start instead of start to stop.
  4. Alter the LSB headers so that both scripts run at the right times during shutdown/reboot
  5. Install them with update-rc.d .

Here are my changes as a copy/paste bash script (if you want to make the changes manually, the LSB headers I have used are in the patch):

cd /etc/init.d cp bootlogd shutdown-bootlogd cp stop-bootlogd shutdown-start-bootlogd echo -e 'diff -ur ./shutdown-bootlogd /etc/init.d/shutdown-bootlogd --- ./shutdown-bootlogd\t2014-02-20 13:59:23.426109512 +0000 +++ /etc/init.d/shutdown-bootlogd\t2014-02-20 11:10:56.238656828 +0000 @@ -1,14 +1,13 @@ #! /bin/sh -### BEGIN INIT INFO -# Provides: bootlogd -# Required-Start: mountdevsubfs -# X-Start-Before: hostname keymap keyboard-setup procps pcmcia hwclock hwclockfirst hdparm hibernate-cleanup lvm2 -# Required-Stop: -# Default-Start: S -# Default-Stop: -# Short-Description: Start or stop bootlogd. -# Description: Starts or stops the bootlogd log program -# which logs boot messages. +### BEGIN INIT INFO +# Provides: shutdown-bootlogd +# Required-Start: +# Required-Stop: umountroot halt reboot +# Default-Start: +# Default-Stop: 0 6 +# X-Stop-After: umountfs +# Short-Description: Stop bootlogd at shutdown. +# Description: ### END INIT INFO PATH=/sbin:/bin # No remote fs at start diff -ur ./shutdown-start-bootlogd /etc/init.d/shutdown-start-bootlogd --- ./shutdown-start-bootlogd\t2014-02-20 13:59:23.430107513 +0000 +++ /etc/init.d/shutdown-start-bootlogd\t2014-02-20 11:10:56.238656828 +0000 @@ -1,24 +1,24 @@ #! /bin/sh ### BEGIN INIT INFO -# Provides: stop-bootlogd -# Required-Start: $local_fs $all -# Required-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: -# Short-Description: Stop bootlogd -# Description: See the init.d/bootlogd script +# Provides: shutdown-start-bootlogd +# Required-Start: +# Required-Stop: $local_fs $all +# Default-Start: +# Default-Stop: 0 6 +# Short-Description: Start or stop bootlogd at shutdown. +# Description: ### END INIT INFO -NAME=stop-bootlogd +NAME=shutdown-start-bootlogd DAEMON=/sbin/bootlogd [ -x "$DAEMON" ] || exit 0 case "$1" in - start) -\t/etc/init.d/bootlogd stop + stop) +\t/etc/init.d/bootlogd start \t;; - stop|restart|force-reload) + start|restart|force-reload) \t# No-op \t;; status) ' | patch update-rc.d shutdown-bootlogd defaults update-rc.d shutdown-start-bootlogd defaults 

All messages that appear before bootlogd is stopped will be stored in /var/log/boot . bootlogd removes the escape characters from the text stream. The following ( bash ) command will display the log in colour, as it appears during shutdown:

sed $'s/\^\[/\E/g;s/\[1G\[/\[27G\[/' /var/log/boot | less -r 

The location of the log can be changed by further editing the scripts. Unfortunately every appearance of the file must be changed (also, replacing /ver/log/boot isn’t enough as the script does a cd to /var/log at one point).

Читайте также:  Максимальное количество памяти linux

The above will also only work if /var/log is on the rootfs. If not the dependencies need to be reworked so that umountfs is done after bootlogd is stopped. Or else log to a file on the rootfs.

Источник

How to find out who/what caused a reboot/shutdown?

On a Linux machine that runs systemd, is there any way to see what or who issued a shutdown or reboot?

2 Answers 2

Examine the system logs of the previous boot with sudo journalctl -b -1 -e .

Are you sure it’s not one of «power interruption/spike», «CPU overheat», .

On MY system (Ubuntu 16.04,6),

sudo journalctl | grep shutdown Jan 29 12:58:07 bat sudo[14365]: walt : TTY=pts/0 ; PWD=/home/walt ; USER=root ; COMMAND=/sbin/shutdown now Feb 12 11:23:59 bat systemd[1]: Stopped Ubuntu core (all-snaps) system shutdown helper setup service. Feb 19 09:35:18 bat ureadahead[437]: ureadahead:lxqt-session_system-shutdown.png: Ignored relative path Feb 19 09:35:18 bat ureadahead[437]: ureadahead:gshutdown_gshutdown.png: Ignored relative path Feb 19 09:35:18 bat ureadahead[437]: ureadahead:mate-gnome-main-menu-applet_system-shutdown.png: Ignored relative path Feb 27 16:45:40 bat systemd-shutdown[1]: Sending SIGTERM to remaining processes. Mar 05 17:53:27 bat systemd-shutdown[1]: Sending SIGTERM to remaining processes. Mar 15 09:57:45 bat systemd[1]: Stopped Ubuntu core (all-snaps) system shutdown helper setup service. Mar 21 17:40:30 bat systemd[1]: Stopped Ubuntu core (all-snaps) system shutdown helper setup service. Apr 15 18:16:37 bat systemd[1]: Stopped Ubuntu core (all-snaps) system shutdown helper setup service. . 

The first line shows when user walt did a sudo shutdown now .

Источник

Оцените статью
Adblock
detector