How to Filter and Analyse Kernel Ring Buffer Messages Using dmesg in Linux

When Linux boots or operates under heavy production workloads, the operating system kernel continuously initialises hardware controllers, allocates memory structures, discovers peripheral devices, and responds to physical hardware faults. Because these events occur long before user-space logging daemons (like systemd-journald or rsyslog) are loaded into memory, the Linux kernel logs early events into an in-memory cyclic storage structure known as the kernel ring buffer. The primary diagnostic utility used to inspect, filter, and extract these critical kernel-level events is dmesg (Diagnostic Message). Mastering dmesg enables systems engineers and administrators to troubleshoot hardware crashes, memory faults, and driver panics efficiently.

Understanding the Kernel Ring Buffer Architecture

The kernel ring buffer is a fixed-size circular memory buffer allocated directly within kernel memory space:

  • Circular Nature: When the buffer reaches its maximum allocated capacity (typically 512 KB to several megabytes), newly generated kernel messages overwrite the oldest records, ensuring the kernel never exhausts system RAM recording diagnostics.
  • Immediate Availability: Unlike text files in /var/log/, the ring buffer exists in volatile memory and is accessible even if local storage drives are failing, unmounted, or read-only.

Basic dmesg Commands and Human-Readable Timestamps

Executing plain dmesg outputs thousands of lines of raw text where timestamps are displayed as floating-point seconds elapsed since system boot (e.g., [ 14.285901]):

  1. To display messages with human-readable wall-clock timestamps:
dmesg -T

The -T (human-readable time) flag converts relative seconds into conventional timestamps (e.g., [Mon Oct 20 05:45:12 2026]), allowing you to correlate kernel incidents with application error logs.

  1. To paginate through extensive output without losing terminal history, pipe into a pager with colour support preserved:
dmesg -T -L | less -R

Filtering by Log Level and Severity with –level

The Linux kernel categorises every event using standard syslog severity levels: emerg (0), alert (1), crit (2), err (3), warn (4), notice (5), info (6), and debug (7). Sifting through informational messages during an outage wastes valuable time. You can filter exclusively for errors and critical warnings:

sudo dmesg -l err,crit,alert,emerg -T

This filters out routine notifications, isolating disk I/O errors, Out-Of-Memory (OOM) killer invocations, hardware MCE (Machine Check Exceptions), and kernel segfaults.

Filtering by Subsystem Facility with –facility

Kernel messages are tagged by the originating hardware or software facility:

sudo dmesg -f daemon,kernel,driver

Common facilities include kern (kernel code), user (user-space processes), daemon (system daemons), and auth (security subsystem). Combining --facility and --level enables surgical diagnostics:

sudo dmesg --facility=kern --level=err -T

Monitoring Kernel Events in Real Time with –follow

When hotplugging physical hardware—such as inserting a new NVMe drive, connecting a USB network interface, or debugging external Thunderbolt docks—monitoring kernel event generation live is invaluable:

sudo dmesg -wH
  • -w (--follow): Instructs dmesg to remain open and stream incoming kernel messages as they occur in real time (similar to tail -f).
  • -H (--human): Formats output with colour-coded severity highlights, relative timestamps, and humanised prefixes. Press Ctrl + C to terminate the live monitoring stream.

Clearing the Ring Buffer for Isolated Diagnostics

When running controlled hardware benchmarks or reproducing specific driver faults, clearing prior history simplifies analysis:

sudo dmesg -c

The -c (clear) flag dumps the current contents of the ring buffer to the console and immediately clears the buffer in memory. Any subsequent dmesg command will display strictly events generated after the clearing command was executed.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.