Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

Read Kernel Messages

sudo dmesg -T | less
sudo dmesg -T | tail -n 50

Each line is one kernel message, oldest first. Without -T, each line starts with the number of seconds since boot, such as [ 3021.448120]. The newest messages are at the end, which is usually where the answer is.

Why dmesg Needs sudo

Debian and Ubuntu (since 20.10) set the kernel option kernel.dmesg_restrict to 1, so a normal user gets a permission error such as "Operation not permitted" instead of the messages. Other distributions may leave it at 0. Use sudo dmesg. You can check the setting with:

sysctl kernel.dmesg_restrict

Leave the restriction in place: kernel messages can contain memory addresses and hardware details that help an attacker.

Readable Timestamps and Why They Drift

-T turns the seconds since boot into a date and time. The dmesg manual warns that these times can be inaccurate: the kernel's log clock is not updated across suspend and resume, so after a suspend, or a pause of a virtual server, they can be off by minutes or more. When the exact time matters, read the same messages from the journal, which stores the real time of each entry:

sudo journalctl -k --since "1 hour ago"

Follow New Messages

sudo dmesg -Tw

-w waits and prints new messages as they arrive. Leave it running while you attach a disk, restart a network interface, or reproduce a crash. Ctrl+C stops it.

Filter by Level

sudo dmesg -T --level=err,warn
sudo dmesg -T -l err

The levels are emerg, alert, crit, err, warn, notice, info, and debug. -x adds the facility and level to each line.

Find Common Problems

ProblemSearch with
Out of memorygrep -i -E "out of memory|oom"
Disk errorsgrep -i -E "i/o error|ext4|xfs"
Network linkgrep -i "link is"
Program crashesgrep -i segfault

Pipe sudo dmesg -T into each search. What to look for:

  • Out of memory: lines that say the OOM killer was invoked, followed by a line naming the killed process and its PID. Reading that record is covered in the OOM killer guide.
  • Disk errors: I/O errors on a device such as vda or sda, and file system messages saying it was remounted read-only. Back up your data first and report the errors to your hosting provider for a virtual disk. A slow disk without errors is covered in how to check disk I/O.
  • Network: "Link is Down" and "Link is Up" lines from the network driver show an interface losing its connection.
  • Segfaults: a program crashed on a memory error; the line names it.

Useful Options

OptionWhat it does
-THuman-readable time
-wFollow new messages
-lFilter by level
-HReadable output, color, pager
-xShow facility and level

Avoid -c and -C: they clear the ring buffer, and the messages you are looking for go with it.

dmesg or journalctl -k?

The ring buffer has a fixed size and is lost at reboot, so dmesg shows only recent messages of the current boot. If the journal is stored on disk, journalctl -k -b -1 shows the kernel messages from the boot before, which is what you need after a crash. See how to use journalctl.

Was this answer helpful?
Loading...