dmesg — kernel messages: OOM, disk and filesystem errors, segfaults
dmesg prints the kernel ring buffer: messages about disks, filesystems, OOM, crashed programs and hardware.
Cheat sheet
8 commands Printable version-
sudo dmesg -T | tail -20latest messages, with time -
sudo dmesg -l err,criterrors only -
sudo dmesg -x | tailwith the level of each line -
sudo dmesg --since '-10min'the last 10 minutes -
sudo dmesg -Wwait for new messages -
sudo journalctl -k -b -p errkernel errors of this boot -
sudo journalctl -k -b -1the kernel of the previous boot -
sudo dmesg -T | grep -iE 'oom|error|segfault'
Overview
dmesg prints kernel messages: about detected hardware, disks and
filesystems, processes the kernel ended, programs that crashed. Programs
write to their own logs; the kernel writes here.
The ring buffer
The kernel puts messages into the ring buffer — a fixed-size piece of memory: when it is full, new lines push out the oldest ones. Every line starts with seconds since boot:
-T turns the seconds into date and time. dmesg --help warns that after a
suspend this time may be wrong; journalctl -k has the exact time.
Access: dmesg_restrict
Ubuntu sets the kernel parameter kernel.dmesg_restrict = 1, and only root
can read the buffer:
Without sudo, journalctl -k prints -- No entries -- and a hint for the
student: the system journal is readable by the groups adm and
systemd-journal, and student is in neither.
Levels
Every message has a severity level. -x shows it, -l filters by it:
| Level | Example from the training machine |
|---|---|
crit |
EXT4-fs error (device loop0): ext4_lookup:1866: … deleted inode referenced: 12 |
crit |
EXT4-fs (loop0): Remounting filesystem read-only |
err |
Aborting journal on device loop0-8. |
err |
Memory cgroup out of memory: Killed process 1635 (tail) … |
info |
python3[1260]: segfault at 0 ip … error 4 in libc.so.6[…] |
info |
EXT4-fs (loop0): mounted filesystem … r/w with ordered data mode. |
-x puts the facility and level at the start of each line: kern :crit :,
kern :err :. A segfault is info: the filter -l err,crit will not
show it. Look for such lines with grep.
dmesg and journalctl -k
journald copies kernel messages into the journal. journalctl -k shows
them with real time and keeps them longer than the buffer: on the training
machine the journal is on disk (/var/log/journal), so previous boots are
visible too.
| Need | Command |
|---|---|
| kernel of this boot | sudo journalctl -k -b |
| kernel of the previous boot | sudo journalctl -k -b -1 |
| errors and worse only | sudo journalctl -k -p err |
| exact ISO time | sudo journalctl -k -o short-iso |
| message text only | sudo journalctl -k -o cat |
Options
10The main options are in the table below; the full list is dmesg --help.
| Option | What it does | Example |
|---|---|---|
-T --ctime |
Message time as date and clock instead of seconds since boot; may be wrong after a suspend. | sudo dmesg -T | tail |
-l --level LIST |
Only messages of the given levels — emerg, alert, crit, err, warn, notice, info, debug; warn+ means this level and above. | sudo dmesg -l err,crit,alert,emerg |
-x --decode |
Print the facility and level of every line — kern :crit, kern :info. | sudo dmesg -x | tail |
-w --follow |
Print the buffer and wait for new messages, like tail -f. | sudo dmesg -w |
-W --follow-new |
Wait and print only new messages, without the old buffer. | sudo dmesg -W |
--since TIME |
Messages since a moment — '-5min', '2026-10-21 00:30'. | sudo dmesg --since '-10min' |
-H --human |
Human-friendly view — time deltas between lines, colours, a pager. | sudo dmesg -H |
-J --json |
JSON output — for scripts and jq. | sudo dmesg -J | head |
-C --clear |
Clear the kernel ring buffer; journalctl -k keeps the messages, dmesg does not. dangerous | sudo dmesg -C |
-c --read-clear |
Print the buffer and clear it. dangerous | sudo dmesg -c |
Nothing found. Try a shorter query.
Recipes
6Follow the messages
-w first prints the whole buffer — hundreds of boot lines — and then
waits. -W waits right away. A line written to /dev/kmsg lands in the
buffer; <3> at the start means level err.
A crashed program: segfault
The program touched memory that is not its own. The kernel ends it with
SIGSEGV (number 11), the exit code is 139 = 128 + 11 (see
exit-codes), and an info line stays in the buffer:
python3[1557] is the name and PID, segfault at 0 is the address it
touched (0 is a null pointer), in libc.so.6 is the library where it
happened. The line is wrapped here for width. When programs crash often,
the kernel skips some lines and writes show_signal_msg: 61 callbacks
suppressed.
An ext4 filesystem error
ext4 found damage: a directory points to a deleted inode. The program got
Structure needs cleaning. What the kernel does next is set by the error
behaviour in the filesystem superblock (errors=): with remount-ro the
journal is aborted, and writes to the filesystem answer
Input/output error. Details and e2fsck are in
filesystems.
OOM: a process ended for lack of memory
The lines Out of memory: Killed process and Memory cgroup out of memory:
Killed process are the work of the oom-killer; that article shows how
to read the whole report.
A task hung in D
The process stayed in state D longer than kernel.hung_task_timeout_secs
(120 seconds on Ubuntu; here the threshold was lowered to 20). A kernel
stack follows — it shows what the process waits for (see
load-average).
Troubleshooting
5read kernel buffer failed: Operation not permitted
kernel.dmesg_restrict = 1: only root reads the buffer. Use sudo dmesg or
sudo journalctl -k.
journalctl -k prints -- No entries --
Without sudo, a user outside the adm and systemd-journal groups sees
only their own entries. Repeat with sudo.
The buffer does not start at boot, or is empty
The buffer overflowed and old lines were pushed out, or someone cleared it
(dmesg -C). The full history is sudo journalctl -k -b.
No journal boot entry found
The journal has no previous boot: the machine booted once, or the journal
is kept in memory only (/run/log/journal). The list of boots is
journalctl --list-boots.
Time in dmesg -T and the journal differ
-T counts time from boot and ignores suspends. The time in
journalctl -k is recorded at the moment of the message.
Danger zone
1dmesg -C and dmesg -c
Both clear the kernel buffer. After sudo dmesg -C on the training machine
dmesg showed 0 lines while journalctl -k -b still had all 577. Do not
clear the buffer on a server you are investigating: the next person will
have only the journal.
Terms
2- kernel ring buffer
- A fixed-size piece of memory where the kernel writes its messages; when it is full, new lines push out old ones. dmesg reads it (root only on Ubuntu), journalctl -k keeps a copy with exact times.
- segfault (segmentation fault)
- The program touched memory that is not its own; the kernel ends it with SIGSEGV (11), the exit code is 139, and the kernel log gets a line "name[PID]: segfault at address … in library".
See also
- journalctl — the journal of services and the kernel.
- oom-killer — an OOM report in the kernel log.
- filesystems — ext4 errors and
e2fsck. - load-average — state
Dand hung tasks. - exit-codes — 128+N codes: 137, 139.
- kernel — the kernel and its boot parameters.
- kernel-modules — drivers and their messages.
- sysctl —
kernel.dmesg_restrictand other parameters.
Found an inaccuracy? Report an error in the article