Skip to content
systemcoding.dev
Kernels

Read and Filter Kernel Logs With dmesg and journalctl -k

Read the kernel ring buffer with dmesg and the journal with journalctl -k, filter by level and time, follow new messages and avoid clock and permission traps.

7 min read
Summarize in AI
Flat illustration of a magnifier over lines of a log, with the Linux, C++ and C logos.

When a driver fails to load, a disk throws errors or a machine reboots on its own, the explanation is usually already in the kernel log. Two commands read it: dmesg reads the kernel's in-memory ring buffer, and journalctl -k reads the same messages as stored by systemd-journald. They overlap and differ in important ways: one is gone at reboot, the other can persist; one has simple filters, the other has a query language. This post shows the options you will actually use on a Linux 6.12 system with a recent util-linux and systemd, how to filter by severity and time, how to follow a log live, and the limits that trip people up. The log's source side, with levels, is covered in the printk levels post.

Where the log lives

The kernel writes every printk() message into a ring buffer in memory. The buffer has a fixed size, and when it fills, the oldest messages are overwritten. dmesg reads that buffer through /dev/kmsg (or the older syslog() system call). It shows only what the buffer still holds, since the last boot, and a restart clears it.

systemd-journald reads the same stream continuously and stores it in the journal, adding fields such as the boot id and the priority. If the journal is configured as persistent, with Storage=persistent in /etc/systemd/journald.conf or a /var/log/journal directory, messages survive reboots and you can read the previous boot. With the default auto setting, a missing /var/log/journal means volatile storage under /run, which is lost at reboot like the ring buffer.

Check which you have:

Shell
ls -d /var/log/journal 2>/dev/null || echo "journal is volatile"
journalctl --list-boots | tail -n 3
Text
/var/log/journal
-2 3a1b... Fri 2026-11-20 08:12:03 UTC—Sat 2026-11-21 19:40:55 UTC
-1 9c4d... Sat 2026-11-21 19:41:30 UTC—Sun 2026-11-22 22:03:12 UTC
 0 5e7f... Sun 2026-11-22 22:03:50 UTC—Mon 2026-11-23 09:15:01 UTC

Boot ids and times differ on your machine. More than one line means the journal is persistent and you can read earlier boots.

dmesg basics

Shell
dmesg | head -n 3
Text
[    0.000000] Linux version 6.12.0 (builder@host) (gcc (GCC) 14.2.1) #1 SMP PREEMPT_DYNAMIC Fri Nov 14 10:12:41 UTC 2026
[    0.000000] Command line: BOOT_IMAGE=/vmlinuz-6.12.0 root=/dev/sda2 ro quiet
[    0.000000] BIOS-provided physical RAM map:

The number in brackets is seconds since the kernel started its clock, with microseconds. The options that matter:

OptionEffect
-T, --ctimePrint human-readable wall-clock times
-H, --humanHuman output: pager, color, relative times, delta
-w, --followWait for new messages, like tail -f
-W, --follow-newFollow only messages that arrive after the command starts
-l, --level LISTRestrict to levels, comma separated
-f, --facility LISTRestrict to facilities such as kern or daemon
-x, --decodeShow facility and level as words
-r, --rawShow the raw message with the <N> prefix
-k, --kernelKernel messages only (the default facility set)
--since, --untilTime range, on recent util-linux releases
-c, --read-clearPrint, then clear the buffer (root)
-C, --clearClear the buffer without printing (root)
-n LEVELSet the console loglevel (root)

Combine a level filter with human times to see recent problems:

Shell
dmesg -T --level=err,warn | tail -n 4
Text
[Mon Nov 23 09:14:02 2026] nvme nvme0: missing or invalid SUBNQN field.
[Mon Nov 23 09:14:07 2026] ACPI BIOS Error (bug): Could not resolve symbol [\_SB.PCI0.XHC.PS0], AE_NOT_FOUND
[Mon Nov 23 09:14:09 2026] usb 1-3: device descriptor read/64, error -71
[Mon Nov 23 09:21:45 2026] ticker: fifo overrun

Level names are emerg, alert, crit, err, warn, notice, info and debug. A comma list selects exactly those, and the form --level=err+ for "err and more severe" works on recent util-linux, but older versions need the explicit list, so check dmesg --help on your machine.

The clock caveat of -T

-T converts the monotonic timestamp to wall-clock time by subtracting the time since boot from the current time. That is only right if the monotonic clock kept counting during the whole uptime. The kernel's log clock does not advance while the machine is suspended, so after a suspend and resume, dmesg -T shows times that are too early by the total suspend duration. The man page warns about this. For accurate times, use journalctl, which records the real wall-clock time when it receives each message, or dmesg --time-format=iso on a machine that never suspends. Treat -T as approximate on laptops.

Follow a log live

To watch messages arrive while you plug in a device, use -w with a filter:

Shell
sudo dmesg -wH --level=err,warn,info
Text
[Nov23 09:30] usb 1-2: new high-speed USB device number 7 using xhci_hcd
[  +0.120000] usb 1-2: New USB device found, idVendor=0781, idProduct=5581
[  +0.000001] usb-storage 1-2:1.0: USB Mass Storage device detected

-H prints the delta from the previous message in brackets, which is useful for spotting a long gap, such as a driver waiting for a timeout. Press Ctrl-C to stop. -W starts from the present instead of replaying the buffer first.

journalctl -k

The journal's kernel messages are selected by -k or --dmesg. The output has syslog-like timestamps and the host name:

Shell
journalctl -k -b -n 3 --no-pager
Text
Nov 23 09:21:45 host kernel: ticker: fifo overrun
Nov 23 09:25:10 host kernel: usb 1-2: new high-speed USB device number 8 using xhci_hcd
Nov 23 09:25:10 host kernel: usb 1-2: New USB device found, idVendor=0781, idProduct=5581

The options that do the work:

OptionEffect
-kKernel messages only
-b, -b 0The current boot
-b -1The previous boot
-p err, -p err..warningPriority or priority range
-fFollow new entries
-n 50Last 50 entries
--since "10 min ago", --untilTime range, with natural-language times
-g PATTERNShow entries matching a regular expression
-o short-monotonicShow the kernel's seconds-since-boot timestamps
-o jsonMachine-readable output
-rNewest first

The previous boot is the reason many people reach for journalctl. After a crash and reboot, dmesg shows only the new boot, but a persistent journal still holds the lines from just before the crash:

Shell
journalctl -k -b -1 -p err --no-pager | tail -n 5
Text
Nov 22 22:01:50 host kernel: BUG: kernel NULL pointer dereference, address: 0000000000000008
Nov 22 22:01:50 host kernel: #PF: supervisor read access in kernel mode
Nov 22 22:01:50 host kernel: Oops: 0000 [#1] PREEMPT SMP NOPTI
Nov 22 22:01:50 host kernel: CPU: 2 UID: 0 PID: 4411 Comm: cat Tainted: G           O       6.12.0 #1

The last lines before a hard hang may not reach the journal, since the system died before journald could write them. For those, use a serial console or netconsole, covered in the netconsole post.

Searching by pattern and range together:

Shell
journalctl -k --since "09:00" --until "09:30" -g "usb 1-2" --no-pager
Text
Nov 23 09:25:10 host kernel: usb 1-2: new high-speed USB device number 8 using xhci_hcd
Nov 23 09:25:10 host kernel: usb 1-2: New USB device found, idVendor=0781, idProduct=5581

Use -o short-monotonic when you need to compare a journal line with a timestamp in a kernel trace or an oops: it shows the same seconds-since-boot values that dmesg prints, so the two outputs line up.

Which one to use

SituationUse
Quick look at the current bootdmesg
The error happened before the last rebootjournalctl -k -b -1
Need accurate wall-clock timesjournalctl -k
Following a hot-plug eventdmesg -wH
Scripting or filtering by a patternjournalctl -k -g, or dmesg piped to grep
Embedded system with no systemddmesg
Need to match kernel traces by timestampdmesg or journalctl -o short-monotonic

Permissions

By default, on many distributions any user can run dmesg. The sysctl kernel.dmesg_restrict set to 1 limits it to users with CAP_SYSLOG, since the log can reveal addresses and hardware details. If dmesg prints Operation not permitted or read kernel buffer failed, that is the setting at work. Use sudo, or add the user to the systemd-journal or adm group to read the journal without root. Reading /dev/kmsg directly has the same restriction. Also, journalctl -k shows only messages from your boot unless you have permission to read the system journal.

Reading a log for a failure

A practical order for a problem you do not understand:

  1. Start from the end of the log: dmesg | tail -n 50.

  2. Filter errors and warnings: dmesg --level=err,warn.

  3. Search for the device or driver name, such as grep -i nvme or grep ticker.

  4. For something that went wrong over time, look at the lines around the first error, not the last. The first failure usually causes the rest.

  5. If the machine rebooted, read journalctl -k -b -1 for the end of the previous boot.

  6. If lines are missing, check whether the ring buffer wrapped: the first line should be the Linux version banner at time 0. If it is not, the beginning was overwritten, and a larger log_buf_len= boot parameter keeps more.

Also inDebugging
Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.