Skip to content

Linux Foundations / Manage a Linux host ยท Step 44 of 50

Lesson: Kernel LoggingSwitch
โ† Linux Foundations

System administration

Kernel Logging

Read kernel messages about hardware and drivers with dmesg and journalctl.

The kernel reports on hardware detection, drivers, filesystems and serious faults. These messages are essential when a device does not appear or the machine behaves strangely.

The kernel ring buffer

The kernel stores its messages in a fixed-size area of memory called the ring buffer. When it is full, new messages overwrite the oldest ones. Read it with dmesg:

$ sudo dmesg | tail -n 3
[ 5231.120394] usb 1-1: new high-speed USB device number 4 using xhci_hcd
[ 5231.301221] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 5232.330871] sd 2:0:0:0: [sdb] Attached SCSI removable disk

The number in brackets is seconds since boot.

Some distributions restrict dmesg to root through the kernel.dmesg_restrict setting, so you may get "Operation not permitted" without sudo.

Useful options

  • dmesg -T shows readable dates. These can be inaccurate after suspend.
  • dmesg -w waits for and prints new messages.
  • dmesg -H gives a friendlier, paged view.
  • dmesg --level=err,warn filters by severity.
$ sudo dmesg --level=err
$ sudo dmesg | grep -i usb

Plug in a USB device while running sudo dmesg -w and you will see the kernel recognise it.

Kernel messages after a reboot

The ring buffer is lost at reboot. The journal keeps kernel messages too:

$ journalctl -k
$ journalctl -k -b -1

-k shows kernel messages and -b -1 selects the previous boot. The previous boot is only available if the journal is persistent.

On some systems with rsyslog, such as Debian or Ubuntu installations, kernel messages are also written to /var/log/kern.log.

What to look for

  • I/O error lines about a disk may mean failing hardware or cabling.
  • Out of memory: Killed process means the kernel ended a process to recover memory.
  • segfault reports a program that accessed invalid memory.
  • Firmware load failures often explain a device that does not work.

Not every warning is a problem. Many appear on healthy machines, so compare with the time your symptom started.

Try it

Run sudo dmesg -T | less and find the lines about your disks. Then run sudo dmesg --level=err,warn and see what your system complains about.

Check your understanding

Kernel Logging

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.