Linux – How to view all boot messages in Linux after booting

bootdmesglinuxlinux-kernelscrolling

Relevant questions are:

Where Linux places the messages of boot?

Name of log file where boot process is logged

However, these do not answer this question. This question is concerned with how all the boot messages can be viewed.

This is for Gentoo, OpenRC, modern kernels, 4.9.6 if you want to get specific. A generic solution that works for all distributions would however be preferable.

The problem is that sometimes an error or warning will scroll by so quickly that it cannot be seen. Nor is it always possible to simply scroll up for two reasons (even with –noclear in inittab): when switching to the framebuffer scrolling up to the point before the switch too place is no longer possible, and second, that after X starts, switching to console and trying to scroll up doesn't allow scrolling at all until new text is added to the buffer. Sometimes, certain messages are simply not found in dmesg nor /var/log/messages.

How can I view all the messages?

I see someone here https://www.linuxquestions.org/questions/linux-newbie-8/please-how-to-pause-scrolling-messages-at-boot-323772/ suggesting that pressing scroll lock might pause it. However, this is a not very elegant solution at best — some messages will scroll by too quickly, systems can suddenly churn out a lot of text these days when booting.

This is what I ideally want:

  • A dmesg | less type solution, if possible, or some other way of single stepping through the boot process.
  • A way to ensure that everything printed on the screen also gets logged.

Is there a straightforward way to achieve either of these?

I know of one solution:

CONFIG_BOOT_PRINTK_DELAY: Delay each boot printk message by N milliseconds

Strangely I don't seem allowed to even select BOOT_PRINTK_DELAY in my menuconfig, I can find it when searching for it, but under Kernel hacking -> printk and dmesg options ->, I only have "Show timing information on printks" and "Default message log level". Where is the printk delay option? Do I need to enable something else first to make it visible? What? It would be nice to have this as part of an answer, if anyone knows.

But anyway this requires a kernel recompilation which makes this an ugly and invasive hack for a seemingly trivial task. A proper way of doing this would be very much welcome.

Best Answer

So your console has two types of messages:

  • generated by the kernel (via printk);
  • generated by userspace (usually your init system).

Kernel messages are always stored in the kmsg buffer, visible via dmesg. They're also often copied to your syslog. (This also applies to userspace messages written to /dev/kmsg, but those are fairly rare.)

Meanwhile, when userspace writes its fancy boot status text to /dev/console or /dev/tty1, it's not stored anywhere at all. It just goes to the screen and that's it. So I think pretty much any solution – except for Rowan's serial console suggestion – will end up being either very distro-specific (due to each init system performing logging differently) or an "invasive hack" that involves strace or kernel hacking or such.

In the best case, your init system will itself log all important events to the syslog (/var/log/messages or such). For example:

systemd[1]: Starting BIRD routing daemon...
bird[478296]: /etc/bird.conf, line 2: syntax error
systemd[1]: bird.service: Control process exited, code=exited status=1
systemd[1]: Failed to start BIRD routing daemon.

(systemd and upstart also log the services' stdout/stderr as well; many other init systems just redirect it to the console or nowhere.)

Related Question