dmesg

dmesg

The dmesg command in Linux is used to examine or control the kernel ring buffer. The kernel ring buffer is a data structure that stores log messages generated by the kernel, including messages related to hardware devices, drivers, and other kernel-related information. This command is particularly useful for debugging hardware and driver issues.

Understanding dmesg

The dmesg command prints the messages stored in the kernel ring buffer. These messages can include information about the system boot process, hardware detection, driver initialization, and errors.

Basic Usage

To display the messages in the kernel ring buffer, simply run:

dmesg

Example Output

Here’s an example of what the dmesg command might return:

[    0.000000] Linux version 5.4.0-74-generic (buildd@lgw01-amd64-033) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #83-Ubuntu SMP Mon May 3 02:29:45 UTC 2021 (Ubuntu 5.4.0-74.83-generic 5.4.119)
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.4.0-74-generic root=UUID=d1c50b1b-9f8f-49d2-81b1-3629f4d38f2f ro quiet splash vt.handoff=7
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Hygon HygonGenuine
[    0.000000]   Centaur CentaurHauls
[    0.000000]   zhaoxin   Shanghai  
[    0.000000] x86/fpu: x87 FPU will use FXSAVE
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000001fffffff] usable

Key Options

  1. -C / --clear: Clear the ring buffer.

  2. -c / --read-clear: Read and clear the ring buffer.

  3. -D / --console-off: Disable printing messages to the console.

  4. -E / --console-on: Enable printing messages to the console.

  5. -H / --human: Display output in a human-readable format, with timestamps in a readable format.

  6. -T / --ctime: Show human-readable timestamps.

  7. -l / --level [level]: Show messages of a certain log level.

  8. -k / --kernel: Show only kernel messages.

Practical Examples

  1. Display Kernel Messages with Human-Readable Timestamps:

  2. Display Kernel Messages with Human-Readable Formatting:

  3. Filter for Specific Message Levels: To show only error messages:

  4. Clear the Kernel Ring Buffer:

  5. Read and Clear the Kernel Ring Buffer:

  6. Monitor New Kernel Messages in Real-Time:

    This command will keep running and display new messages as they are added to the buffer.

  1. journalctl: For systems using systemd, journalctl can be used to view system logs, including kernel messages.

  2. /var/log/kern.log: Kernel messages are also logged in /var/log/kern.log on some systems. Viewing this file can be done with cat, less, or tail.

  3. /var/log/syslog: General system messages and logs, including kernel messages, can be found in /var/log/syslog on some systems.

Conclusion

The dmesg command is an essential tool for system administrators and users who need to troubleshoot hardware and driver issues. By examining the kernel ring buffer, you can gain valuable insights into the system's hardware interactions and kernel events.

help

Last updated