Hello! Welcome to the next lesson in our journey through Linux system administration.
In our last session, we focused on diagnosing application and service failures by exploring logs in /var/log and using the powerful journalctl command. You learned how to find out why a service failed to start or a user couldn't log in. Those logs are essential for software-level troubleshooting.
Today, we're going deeper—down to the hardware level. What happens when the problem isn't the software, but the physical components it runs on? How do you know if the kernel has recognized a new disk drive, or why a USB device isn't working? For this, we need a different tool.
This lesson is dedicated to mastering dmesg, the command you'll use to inspect kernel ring buffer messages for hardware-related issues. This is your window into the very first conversations between the Linux kernel and the computer's hardware, happening from the moment the system boots up.
1. The Kernel Ring Buffer: The System's First Diary
Before your Linux system can even mount a disk to read or write files (like the logs in /var/log), the kernel is already awake and busy. It's identifying the CPU, checking memory, detecting storage controllers, and initializing network cards. Where do all these very early messages go?
They go into the kernel ring buffer, a small, temporary storage area in your computer's memory (RAM). dmesg (short for "display message" or "driver message") is the command we use to read the contents of this buffer.
Let's watch a short video that explains this concept.
LPIC 1 - 063 - 108.2 (1/3) - System Logging, Concepts, dmesg, Kernel Ring Buffer & logrotate
This clip from the "LPIC 1" series by Jadi provides a great conceptual overview of the kernel ring buffer and introduces the dmesg command.
Watch from 08:27 to 11:18. Focus on understanding: Why a memory buffer is necessary for early boot messages. What kind of information dmesg shows (e.g., boot process, CPU features, hardware initialization).
As you saw, the ring buffer captures everything the kernel does, making dmesg an indispensable tool for diagnosing hardware detection and driver initialization problems.
2. Basic dmesg Usage: Taming the Flood
If you run dmesg on its own, you'll see a massive wall of text scroll by. The first practical skill is learning how to manage this output so you can find what you need. As with many Linux commands, we'll use a pager like less.
Let's look at another practical walkthrough. In the previous lesson, we previewed the dmesg section from the "Understanding Logging" video. Now, let's watch it with a focus on hardware.
Linux Crash Course - Understanding Logging
This segment from Learn Linux TV's "Linux Crash Course - Understanding Logging" demonstrates the basic use of dmesg and points out a real-world example of hardware detection.
Please watch from 21:44 to 24:14. Pay attention to how the command is used to see kernel messages and how it shows the detection of a USB mouse. This is a classic use case for dmesg.
As you can see, simply running dmesg and looking through the output can confirm if the kernel has "seen" a piece of hardware you've connected.
3. Practical Hardware Troubleshooting with dmesg
Now let's get to the core of this lesson: using dmesg to solve real problems. We will use a comprehensive guide as our reference and then apply its techniques to common scenarios you'll face in a data center.
Linux dmesg Command: Syntax, Options, Examples
This article, "Linux dmesg Command: Syntax, Options, Examples" from phoenixNAP, is an excellent, detailed reference. It covers the most important options and use cases you'll need.
Please read the introduction and the sections "Linux dmesg Command Examples" and "dmesg Options". You don't need to memorize every option, but focus on understanding these key techniques: Piping output to less and grep. Searching for specific hardware terms like usb, sda (for disks), and eth (for network cards). Enabling human-readable timestamps with -T. Filtering by log level (e.g., err, warn) with -l. Following new messages in real-time with --follow.
Now that you've reviewed the toolkit, let's apply it. Open a terminal and get ready to practice.
Scenario 1: "I've plugged in a new USB device. Is it detected?"
This is one of the most common uses for dmesg. You've physically connected a device—a keyboard, a mouse, or a USB storage drive—and you need to confirm the system sees it.
-
First, you can monitor the log in real-time. Run this command and then plug in your USB device:
sudo dmesg --followYou should see new lines appear as the kernel detects the device and loads the appropriate driver. Press
Ctrl+Cto stop. -
Alternatively, if the device is already plugged in, you can search the entire buffer. The
grepcommand is your best friend here. The-iflag makes the search case-insensitive.dmesg | grep -i usb
Here is what a successful detection looks like.

If you see output like this, the hardware is recognized. If the device still isn't working, the problem is likely at a higher level (e.g., user-space configuration, missing application drivers), not a kernel/hardware issue.
Scenario 2: "The system booted, but I suspect a hardware or firmware error."
Sometimes, a server will boot but behave incorrectly. You might suspect a problem with a storage controller, a network card, or even the motherboard firmware (BIOS/UEFI). dmesg is the first place to look for errors reported by the kernel.
Instead of searching for a specific device, you can filter the output to show only messages with a certain severity, like errors (err) and warnings (warn).
dmesg -l err,warn

Scenario 3: Correlating Events with a Timestamp
By default, dmesg timestamps are shown as seconds since the kernel started. This is useful for sequencing boot events but difficult to correlate with a real-world clock. If a user reports "the network dropped around 3:15 PM," you need a human-readable timestamp.
The -T (--ctime) flag is the solution.
dmesg -T | less
Now the output is prepended with a standard [Day Mon Date HH:MM:SS YYYY] timestamp. This allows you to scroll directly to the time of a reported incident and see if the kernel logged any relevant hardware events, like a network link going down or a disk I/O error.
4. Important Considerations
Before we conclude, it's crucial to understand a couple of limitations mentioned in the phoenixNAP article.
- Fixed Buffer Size: The kernel ring buffer has a limited size. On a very active system, old messages are pushed out by new ones. This is why it's a ring buffer. If a hardware event happened a long time ago, the message might be gone. This means you should check
dmesgas soon as possible after an incident. - Permissions: While any user can typically run
dmesg, some distributions restrict access to the full log for security reasons. If you get a "permission denied" error or suspect you're not seeing everything, always run the command withsudo:sudo dmesg.
Conclusion
Excellent work. You have now added another critical diagnostic tool to your skillset. While journalctl and /var/log are for services and applications, dmesg is your direct line to the kernel for hardware-level diagnosis.
Key Takeaways:
dmesgreads kernel messages from a temporary memory area called the kernel ring buffer.- It is the primary tool for diagnosing hardware detection, driver, and firmware issues that occur during boot or runtime.
- The most effective way to use
dmesgis by combining it with other tools:dmesg | less: To navigate the large output.dmesg | grep -i <hardware>: To search for specific devices (e.g.,usb,sda,eth).dmesg -T: To get human-readable timestamps for correlating events.dmesg -l err,warn: To quickly find critical errors and warnings.
In our last few lessons, we've focused on things being broken. But what if a server isn't broken, it's just slow? In our next lesson, we will shift our focus from failure analysis to performance analysis. You will learn how to answer the question, "Given a slow server, identify the resource bottleneck (CPU, memory, or I/O) using vmstat, iostat, and iotop."