dmesg — check kernel messages
💬 "dmesg command"
dmesg displays kernel ring buffer messages. Disk errors, network link issues, and OOM kills are recorded here.
Because it is separate from user-space application logs, you should review it together when troubleshooting unexplained problems.
- Concept: Shows kernel messages in chronological order.
- Left: Kernel time in the format [ 12.345678] (seconds elapsed since boot).
- Contents: Drivers, disk I/O errors, OOM killer, link status, and more.
- -T: Converts to human-readable actual time.
Commonly used options
| Option | Description |
|---|---|
| -T | Convert timestamps to actual time |
| -l err,warn | Show only specific levels |
| -k | Show only kernel messages |
| -w / --follow | Follow new messages in real time |
3 essential command combinations
dmesg -T | tail -50— Check recent kernel messagesdmesg -T | grep -i -E 'oom|killed process'— Check whether OOM kills occurreddmesg -T | grep -i -E 'error|fail|i/o'— Find hardware and I/O errors
💬 "Show me an example of safely reverting this command"
Here are situations commonly encountered on live production servers, organized in order.
Step 1 · Check recent messages
View recent logs related to boot and devices.
dmesg -T | tail -50
Step 2 · Check for OOM
Check whether a process was killed due to insufficient memory.
dmesg -T | grep -i -E 'oom|killed process'
Step 3 · Check disk errors
Check for I/O errors.
dmesg -T | grep -i -E 'i/o error|medium error|ata'
How to use this in practice
1. Process suddenly dies
Situation — An app process terminates without warning.
dmesg -T | grep -i -E 'oom|killed process'
Result — If you see the message Out of memory: Killed process, the OOM killer terminated the process.
Point — Also check memory usage, and adjust swap or memory limits if needed.
2. Unexplained reboot
Situation — There is a record that the server rebooted in the early morning.
dmesg -T | head -30
Result — In the early boot messages, check hardware initialization and traces of the previous shutdown.
Point — When used together with journalctl --list-boots, you can identify the exact reboot time.
Important notes
- The ring buffer has a limited size, so old messages disappear. Use journal/rsyslog for permanent retention.
- Kernel time alone makes it hard to know the actual time, so use -T.
- Some distributions restrict dmesg access with kernel.dmesg_restrict.
Actual output
This is the result of checking for OOM kills and disk I/O errors.
!dmesg command output: kernel OOM and I/O errors
Live production server
Source (HTML): https://games.aidebatehub.com/programs/linux/logs/dmesg.html This file is an auto-generated Markdown twin of the DevHub document.
AI Knowledge Hub
Visitor Comments