Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

dmesg Command Guide for Reading Kernel Messages

dmesg prints the kernel ring buffer — the messages the kernel wrote while booting and while hardware, drivers, and the filesystem have been talking since.


What is dmesg, and Why Use It?

When the kernel starts, it detects hardware, loads drivers, mounts filesystems, and reports anything that went wrong. Those messages go into a fixed-size buffer in memory — the ring buffer — which is exactly what dmesg prints. When a USB device is rejected, a disk starts failing, or the out-of-memory killer terminates a process, dmesg is where you find out. It is the closest thing Linux has to a hardware diary.

Why Learn dmesg?

  • Hardware problems show up here first — a failing disk, a rejected device, a bad USB cable.
  • It explains boot failures — the messages that scroll past too fast to read are all in the buffer.
  • The OOM killer writes here — when a process dies for no visible reason, this is the evidence.
  • It is one command — no service to query, no files to find.
  • It works when nothing else does — the ring buffer is available even when systemd is unhappy.

When Should You Use dmesg?

Use it when hardware seems broken, a device is not detected, a process was killed unexpectedly, or the machine failed to boot cleanly. On a systemd system, journalctl -k reads the same messages with time filtering — reach for dmesg when you want raw output or are on a minimal system.


1. The Basics

dmesg

That is a lot of lines. In practice you almost always filter:

dmesg | tail -20        # what happened most recently
dmesg | less            # read it properly
dmesg --human           # readable timestamps and sizes

Example with --human:

[   0.000000] Linux version 6.8.0-45-generic (buildd@lcy02) #50-Ubuntu SMP
[   1.204331] usb 1-1: new high-speed USB device number 2 using ehci-pci
[  12.884120] EXT4-fs (sda2): mounted filesystem with ordered data mode

--human is worth the habit. It converts raw timestamps and byte counts into seconds-since-boot and units you can read.


2. Filter by Level

The kernel tags each message with a severity:

dmesg --level=err                # errors only
dmesg --level=err,warn           # errors and warnings
dmesg --level=emerg,alert,crit   # the things that should never happen
LevelNumberMeaning
emerg0System is unusable
alert1Action must be taken immediately
crit2Critical condition
err3Error condition
warn4Warning
notice5Normal but significant
info6Informational
debug7Debugging messages

A first pass on any mystery:

dmesg --level=err,warn --human | tail -30

3. Follow Live

To watch events as they happen — plug in a device and see what the kernel says:

dmesg --follow

Or with the classic text tools:

dmesg -w
dmesg | tail -f

Real example of a device being rejected:

[42188.114902] usb 1-2: new full-speed USB device number 5 using ohci-pci
[42188.402881] usb 1-2: device descriptor read/64, error -71
[42188.712044] usb 1-2: device not accepting address 5, error -71

error -71 on a fresh plug-in almost always means a bad cable or an unpowered port, not a broken device.

When a USB device does nothing, dmesg -w while you plug it in tells you more in five seconds than any amount of guessing.


4. Find Specific Things

By keyword

dmesg | grep -i error
dmesg | grep -i sda        # a disk
dmesg | grep -i 'out of memory'
dmesg | grep -i firmware   # driver complaints

By time since boot

dmesg --since "5 min ago"
dmesg --since "2026-12-05 09:00:00"

These use the same time syntax as journalctl, which makes them consistent to remember.

Show the timestamp only

dmesg --time-format=iso | tail -10
2026-12-05T09:14:22,884120+00:00   6.8.0-45-generic EXT4-fs (sda2): mounted

5. The Problems dmesg Catches

Out of memory

When the kernel runs out of memory it kills a process to survive. The victim is named here:

dmesg | grep -i "killed process"
[88412.001922] Out of memory: Killed process 2841 (postgres) total-vm:4821040kB

If you see this, the answer is in the free and vmstat pages.

Disk errors

dmesg | grep -iE 'i/o error|ata|nvme|sda'
[90112.441092] sd 0:0:0:0: [sda] tag#0 FAILED Result: hostbyte=DID_OK
[90112.441118] Buffer I/O error on dev sda2, logical block 12884

Repeated I/O errors on a healthy system mean a failing disk. Back up before you do anything else.

Boot messages

dmesg | head -40

This shows kernel version, CPU detection, memory total, and which filesystems mounted — the fastest way to confirm what hardware the kernel actually found.


Common Pitfalls

Forgetting that the buffer is finite. The ring buffer holds a fixed number of messages and overwrites the oldest. On a busy system, early boot messages may already be gone. Read them from the journal instead:

journalctl -k -b

Forgetting sudo on some systems. Kernel message access can be restricted by kernel.dmesg_restrict. If you get dmesg: read kernel buffer failed: Operation not permitted:

sudo dmesg | tail -20
# or check the setting
cat /proc/sys/kernel/dmesg_restrict

Confusing dmesg with a log file. Nothing is written to /var/log automatically. If you need a permanent record, save it:

sudo dmesg > boot-dmesg.txt

Trusting the timestamps literally. By default they are seconds since boot, which reset every restart. Use --human or --time-format=iso when you need real times.

Reading it as the whole story. A missing message is not evidence that nothing happened. Absence in dmesg means the kernel did not log it, not that it did not occur.


PageRelationship
journalctljournalctl -k reads the same kernel messages with time filtering
var-logWhere persistent kernel and system logs live on older setups
freeConfirms the memory pressure behind an OOM kill
vmstatShows the paging and CPU state that led to a kill
unameKernel version — the first line of dmesg output

dmesg Cheatsheet

CommandDoes
dmesgPrint the kernel ring buffer
dmesg --humanReadable timestamps and sizes
dmesg -wFollow live
dmesg --level=errErrors only
dmesg --level=err,warnErrors and warnings
dmesg --since "10 min ago"Recent messages
dmesg --time-format=isoReal timestamps
dmesg | tail -20Most recent lines
dmesg | grep -i errorFilter by keyword
dmesg | head -40Boot messages
sudo dmesgWhen permissions block the buffer

When hardware behaves strangely, the kernel already wrote it down.