Skip to content
Home » dmesg: The Secret Weapon for Debugging Your Linux System

dmesg: The Secret Weapon for Debugging Your Linux System

Have you ever encountered a strange error message on your Linux system, and had no idea where to start troubleshooting? If so, then dmesg might just be the tool you’ve been looking for.

dmesg is a command that displays the kernel’s message buffer. When the kernel boots, it logs various messages to this buffer, including hardware detection, system initialization, and driver-specific messages. The dmesg command allows you to view these messages in real-time, or after the fact by reading the buffer from a file.

One thing that most people don’t know about dmesg is that it can also be used to control the kernel’s logging behavior. By using the -n flag, you can specify the log level (the importance of the message), and the -C flag can be used to clear the buffer.

Here are some key points to remember about dmesg:

  • It displays the kernel’s message buffer
  • It can be used to control the kernel’s logging behavior
  • It can be used to troubleshoot issues on your Linux system

Now let’s look at some examples of how dmesg can be used to increase productivity and efficiency:

Viewing hardware detection messages

When you boot your system, dmesg can show you messages related to hardware that was detected by the kernel. This can be helpful if you are trying to troubleshoot hardware issues, or simply want to know what hardware is present on your system.

$ dmesg | grep -i "hardware"
[    0.000000] BIOS-e820: [mem 0x0000000000001000-0x000000000009dfff] usable
[    0.000000] BIOS-e820: [mem 0x000000000009e000-0x000000000009ffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000003fffffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000040000000-0x00000000ffffffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x00000001ffffffff] usable
[    0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.776886] e1000: Intel(R) PRO/1000 Network Driver - version 7.3.21-k8-NAPI
[    0.776888] e1000: Copyright (c) 1999-2006 Intel Corporation.
[    0.776930] e1000 0000:00:19.0: PCI INT A -> GSI 16 (level, low) -> IRQ 16
[    0.776934] e1000 0000:00:19.0: setting latency timer to 64
[    0.777226] e1000: 0000:00:19.0: eth0: (PCI:33MHz:32-bit) 00:11:22:33:44:55
[    0.777227] e1000: 0000:00:19.0: eth0: Intel(R) PRO/1000 Network Connection
[    0.777322] e1000: eth0: e1000_watchdog

Troubleshooting boot issues

If you are having issues booting your system, dmesg can be a helpful tool for identifying the cause of the problem. By using the grep command, you can search for specific keywords in the message buffer, such as “error” or “failure.”

$ dmesg | grep -i "error"
[    0.634640] EXT4-fs (sda1): re-mounted. Opts: errors=remount-ro
[    3.038150] snd_hda_intel 0000:00:1b.0: azx_get_response timeout, switching to polling mode: last cmd=0x000f0000
[    3.038181] snd_hda_intel 0000:00:1b.0: Codec #0 probe error; disabling it...
[    3.038185] snd_hda_intel 0000:00:1b.0: Codec #2 probe error; disabling it...
[    3.038187] snd_hda_intel 0000:00:1b.0: Codec #3 probe error; disabling it...
[    3.038189] snd_hda_intel 0000:00:1b.0: Codec #4 probe error; disabling it...
[    3.038191] snd_hda_intel 0000:00:1b.0: Codec #5 probe error; disabling it...
[    3.038193] snd_hda_intel 0000:00:1b.0: Codec #6 probe error; disabling it...
[    3.038195] snd_hda_intel 0000:00:1b.0: Codec #7 probe error; disabling it...
[    3.038197] snd_hda_intel 0000:00:1b.0: Codec #8 probe error; disabling it...
[    3.038199] snd_hda_intel 0000:00:1b.0: Codec #9 probe error; disabling it...
[    3.038201] snd_hda_intel 0000:00:1b.0: Codec #10 probe error; disabling it...
[    3.038203] snd_hda_intel 0000:00:1b.0: Codec #11 probe error; disabling it...
[    3.038205] snd_hda_intel 0000:00:1b.0: Codec #12 probe error; disabling it...
[    3.038207] snd_hda_intel 0000:00:1b.0: Codec #13 probe error; disabling it...
[    3.038209] snd_hda_intel 0000:00:1b.0: Codec #14 probe error; disabling it...
[    3.038211] snd_hda_intel 0000:00:1b.0: Codec #15 probe error; disabling it...
[    3.038213] snd_hda_intel 0000:00:1b.0: Codec #16 probe error; disabling it...
[    3.038215] snd_hda_intel 0000:00:1b.0: Codec #17 probe error; disabling it...

Debugging driver issues

If you are experiencing issues with a specific driver, dmesg can be used to view messages related to that driver. For example, if you are having issues with your network driver, you can use dmesg to view messages related to the e1000 driver:

$ dmesg | grep -i "e1000"
[    0.776886] e1000: Intel(R) PRO/1000 Network Driver - version 7.3.21-k8-NAPI
[    0.776888] e1000: Copyright (c) 1999-2006 Intel Corporation.
[    0.776930] e1000 0000:00:19.0: PCI INT A -> GSI 16 (level, low) -> IRQ 16
[    0.776934] e1000 0000:00:19.0: setting latency timer to 64
[    0.777226] e1000: 0000:00:19.0: eth0: (PCI:33MHz:32-bit) 00:11:22:33:44:55
[    0.777227] e1000: 0000:00:19.0: eth0: Intel(R) PRO/1000 Network Connection
[    0.777322] e1000: eth0: e1000_watchdog

Monitoring kernel log levels

By using the n flag, you can specify the log level of the messages that you want to view. For example, the following command will only display messages with a log level of “warning” or higher:

$ dmesg -n warning
[    3.038150] snd_hda_intel 0000:00:1b.0: azx_get_response timeout, switching to polling mode: last cmd=0x000f0000
[    3.038181] snd_hda_intel 0000:00:1b.0: Codec #0 probe error; disabling it...
[    3.038185] snd_hda_intel 0000:00:1b.0: Codec #2 probe error; disabling it...
[    3.038187] snd_hda_intel 0000:00:1b.0: Codec #3 probe error; disabling it...
[    3.038189] snd_hda_intel 0000:00:1b.0: Codec #4 probe error; disabling it...
[    3.038191] snd_hda_intel 0000:00:1b.0: Codec #5 probe error; disabling it...
[    3.038193] snd_hda_intel 0000:00:1b.0: Codec #6 probe error; disabling it...
[    3.038195] snd_hda_intel 0000:00:1b.0: Codec #7 probe error; disabling it...
[    3.038197] snd_hda_intel 0000:00:1b.0: Codec #8 probe error; disabling it...
[    3.038199] snd_hda_intel 0000:00:1b.0: Codec #9 probe error; disabling it...
[    3.038201] snd_hda_intel 0000:00:1b.0: Codec #10 probe error; disabling it...
[    3.038203] snd_hda_intel 0000:00:1b.0: Codec #11 probe error; disabling it...
[    3.038205] s

Clearing the kernel message buffer

If you want to clear the kernel message buffer, you can use the C flag. This can be helpful if you want to start a fresh log, or if the buffer is full and you want to free up some space.

$ dmesg -C

Now it’s your turn to test your knowledge of dmesg. Can you think of any other ways that dmesg can be used to increase productivity or efficiency on a Linux system?

Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen − one =