Table of Contents
In this article, I will take you through 15 dmesg command examples that can be used for troubleshooting any Linux Servers issue. dmesg, also sometimes abbreviated as "driver message" or "display message" is an open source utility or command that is used to examine or control kernel ring buffer. dmesg command fetches the logs from /var/log/dmesg file and display it on the output. To understand its usage, we will see some real world examples which can help you in troubleshooting multiple Linux Servers issue. More about dmesg command.
Synopsis
dmesg [options]
dmesg --clear
dmesg --read-clear [options]
dmesg --console-level level
dmesg --console-on
dmesg --console-off
15 dmesg command examples for Troubleshooting Linux Servers
Also Read: A Complete Guide to Supervisor in Linux with Examples
Example 1: How to check dmesg command version
To check the current dmesg command version, you need to use dmesg --version
command as shown below.
root@cyberithub:~# dmesg --version dmesg from util-linux 2.34
Example 2: Show all the Messages from Linux Buffer
If you want to print all the messages from the Linux buffer then all you need to do is run dmesg
command as shown below.
root@cyberithub:~# dmesg
[ 0.000000] Linux version 5.13.0-28-generic (buildd@lgw01-amd64-035) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022 (Ubuntu 5.13.0-28.31~20.04.1-generic 5.13.19)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.13.0-28-generic root=UUID=7658bef9-504f-4dfb-a776-a05e2ac3219f ro quiet splash
[ 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: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
.............................................................
Example 3: How to Colorize the Output using dmesg command
If you are looking to colorize the dmesg output then you need to use -L
option as shown below. You can also set some optional argument where --color
can be set to auto
, never
or always
.
root@cyberithub:~# dmesg -L [ 0.000000] Linux version 5.13.0-28-generic (buildd@lgw01-amd64-035) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022 (Ubuntu 5.13.0-28.31~20.04.1-generic 5.13.19) [ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.13.0-28-generic root=UUID=7658bef9-504f-4dfb-a776-a05e2ac3219f ro quiet splash [ 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: Supporting XSAVE feature 0x001: 'x87 floating point registers' ........................................................................
Example 4: How to Enable Timestamp in dmesg logs
If you want to enable timestamp in dmesg logs then you need to use -T
option with dmesg command as shown below.
root@cyberithub:~# dmesg -T
[Thu Feb 10 10:18:30 2022] Linux version 5.13.0-28-generic (buildd@lgw01-amd64-035) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022 (Ubuntu 5.13.0-28.31~20.04.1-generic 5.13.19)
[Thu Feb 10 10:18:30 2022] Command line: BOOT_IMAGE=/boot/vmlinuz-5.13.0-28-generic root=UUID=7658bef9-504f-4dfb-a776-a05e2ac3219f ro quiet splash
[Thu Feb 10 10:18:30 2022] KERNEL supported cpus:
[Thu Feb 10 10:18:30 2022] Intel GenuineIntel
[Thu Feb 10 10:18:30 2022] AMD AuthenticAMD
[Thu Feb 10 10:18:30 2022] Hygon HygonGenuine
[Thu Feb 10 10:18:30 2022] Centaur CentaurHauls
[Thu Feb 10 10:18:30 2022] zhaoxin Shanghai
[Thu Feb 10 10:18:30 2022] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[Thu Feb 10 10:18:30 2022] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[Thu Feb 10 10:18:30 2022] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
..........................................................................
Example 5: How to Display all Error related logs
You also have the option to display log of different levels. Logs are basically divided into eight different levels - emerg
, alert
, crit
, err
, warn
, notice
, info
and debug
. You can display log based on these levels by using --level
option. For example to display all error related dmesg log, you need to use dmesg --level=err
command as shown below.
root@cyberithub:~# dmesg --level=err
[ 18.018815] [drm:vmw_host_log [vmwgfx]] *ERROR* Failed to send host log message.
Similarly if you want to display all warning related logs then you need to use dmesg --level=warn
command as shown below.
root@cyberithub:~# dmesg --level=warn
[ 0.038547] unchecked MSR access error: WRMSR to 0x3a (tried to write 0x0000000000000001) at rIP: 0xffffffffa4c7fa14 (native_write_msr+0x4/0x30)
[ 0.038552] Call Trace:
[ 0.038554] <TASK>
[ 0.038554] ? init_ia32_feat_ctl+0xb8/0x280
[ 0.038558] init_intel+0xee/0x490
[ 0.038560] identify_cpu+0x2a0/0x570
[ 0.038561] identify_boot_cpu+0x10/0x9a
[ 0.038564] check_bugs+0x2a/0x8a5
[ 0.038566] start_kernel+0x69f/0x6d4
[ 0.038568] x86_64_start_reservations+0x24/0x26
[ 0.038570] x86_64_start_kernel+0x8b/0x8f
[ 0.038571] secondary_startup_64_no_verify+0xc2/0xcb
[ 0.038574] </TASK>
Example 6: How to display only Daemon related Logs
If you want to restrict output to some given list of facilities then you need to pass all the facility name separated by comma to --facility
option. For example, to restrict the output to daemon facility you need to use dmesg --facility=daemon
command as shown below. Other facilities available to use are kern
, user
, mail
, daemon
, auth
, lpr
and news
.
root@cyberithub:~# dmesg --facility=daemon
[ 10.760596] systemd[1]: Inserted module 'autofs4'
[ 11.300352] systemd[1]: systemd 245.4-4ubuntu3.15 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid)
[ 11.300413] systemd[1]: Detected virtualization oracle.
[ 11.300420] systemd[1]: Detected architecture x86-64.
[ 11.326235] systemd[1]: Set hostname to <cyberithub>.
[ 15.244380] systemd[1]: Created slice system-modprobe.slice.
[ 15.244803] systemd[1]: Created slice system-systemd\x2dfsck.slice.
[ 15.245047] systemd[1]: Created slice User and Session Slice.
[ 15.245140] systemd[1]: Started Forward Password Requests to Wall Directory Watch.
[ 15.245479] systemd[1]: Set up automount Arbitrary Executable File Formats File System Automount Point.
[ 15.245555] systemd[1]: Reached target User and Group Name Lookups.
[ 15.245576] systemd[1]: Reached target Remote File Systems.
Example 7: How to Monitor Real Time dmesg logs
If you want to monitor dmesg output on real time then you need to use --follow
option with dmesg command as shown below.
root@cyberithub:~# dmesg --follow
[ 0.000000] Linux version 5.13.0-28-generic (buildd@lgw01-amd64-035) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022 (Ubuntu 5.13.0-28.31~20.04.1-generic 5.13.19)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.13.0-28-generic root=UUID=7658bef9-504f-4dfb-a776-a05e2ac3219f ro quiet splash
[ 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: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
Example 8: How to Display Raw Message Buffer
If you want to display raw message buffer then you need to use -r
option with dmesg command as shown below.
root@cyberithub:~# dmesg -r
<5>[ 0.000000] Linux version 5.13.0-28-generic (buildd@lgw01-amd64-035) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022 (Ubuntu 5.13.0-28.31~20.04.1-generic 5.13.19)
<6>[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.13.0-28-generic root=UUID=7658bef9-504f-4dfb-a776-a05e2ac3219f ro quiet splash
<6>[ 0.000000] KERNEL supported cpus:
<6>[ 0.000000] Intel GenuineIntel
<6>[ 0.000000] AMD AuthenticAMD
<6>[ 0.000000] Hygon HygonGenuine
<6>[ 0.000000] Centaur CentaurHauls
<6>[ 0.000000] zhaoxin Shanghai
<6>[ 0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
..............................................................................
Example 9: How to Disable or Enable Messages to the Console
If you want to disable dmesg messages to the console then you need to use dmesg -D
command as shown below.
root@cyberithub:~# dmesg -D
If you want to enable dmesg messages to the console then you need to use dmesg -E
command as shown below.
root@cyberithub:~# dmesg -E
Example 10: How to force dmesg to use Syslog
If you want to force dmesg to use Syslog then you need to use -S
option with dmesg command as shown below. Using this option, you can force dmesg to get the log data from Syslog instead of /dev/kmsg
.
root@cyberithub:~# dmesg -S
[ 0.000000] Linux version 5.13.0-28-generic (buildd@lgw01-amd64-035) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022 (Ubuntu 5.13.0-28.31~20.04.1-generic 5.13.19)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.13.0-28-generic root=UUID=7658bef9-504f-4dfb-a776-a05e2ac3219f ro quiet splash
[ 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: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ 0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
..........................................................................
Example 11: How to Check all the dmesg logs related to a Device
You can dmesg logs for all kind of devices. For example, if you want to check the logs for USB devices then you need to use dmesg | grep -i usb command as shown below.
root@cyberithub:~# dmesg | grep -i usb
Similarly, you can check for other devices as well by using below command.
root@cyberithub:~# dmesg | grep -i dma root@cyberithub:~# dmesg | grep -i scsi root@cyberithub:~# dmesg | grep -i acpi root@cyberithub:~# dmesg | grep -i memory root@cyberithub:~# dmesg | grep -i tty
Example 12: How to Clear Ring Buffer using dmesg command
If you want to clear the ring buffer then you need to use -C
option with dmesg command as shown below.
root@cyberithub:~# dmesg -C
If you want to clear the ring buffer after first reading the contents then you need to use -c
option.
root@cyberithub:~# dmesg -c
Example 13: How to Display top/bottom lines of dmesg logs
If you want to display first n lines of dmesg command output then you need to use head command with dmesg. For example, here we are printing top 12 lines of dmesg output by using dmesg | head -n 12 command as shown below.
NOTE:
head
command will display top 10 lines of a file/output.root@cyberithub:~# dmesg | head -n 12
[ 0.000000] Linux version 5.13.0-28-generic (buildd@lgw01-amd64-035) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022 (Ubuntu 5.13.0-28.31~20.04.1-generic 5.13.19)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.13.0-28-generic root=UUID=7658bef9-504f-4dfb-a776-a05e2ac3219f ro quiet splash
[ 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: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
Similarly, if you want to display last n lines of dmesg logs then you need to use tail command with dmesg. In the below example, we are displaying the last 4 lines of dmesg command output by using dmesg | tail -n 4
command as shown below.
NOTE:
tail
command will display the last 10 lines of a file/output.root@cyberithub:~# dmesg | tail -n 4
[ 391.977453] audit: type=1400 audit(1644518831.457:39): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.snap-store.hook.configure" pid=1692 comm="apparmor_parser"
[ 392.823829] audit: type=1400 audit(1644518832.309:40): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.snap-store.snap-store" pid=1693 comm="apparmor_parser"
[ 393.776011] audit: type=1400 audit(1644518833.261:41): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.snap-store.ubuntu-software" pid=1694 comm="apparmor_parser"
[ 394.944664] audit: type=1400 audit(1644518834.429:42): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.snap-store.ubuntu-software-local-file" pid=1696 comm="apparmor_parser"
Example 14: How to Check the Man page of dmesg command
If you want to check the man page of dmesg command then you need to use man dmesg
command as shown below.
root@cyberithub:~# man dmesg
DMESG(1) User Commands DMESG(1)
NAME
dmesg - print or control the kernel ring buffer
SYNOPSIS
dmesg [options]
dmesg --clear
dmesg --read-clear [options]
dmesg --console-level level
dmesg --console-on
dmesg --console-off
DESCRIPTION
dmesg is used to examine or control the kernel ring buffer.
The default action is to display all messages from the kernel ring buffer.
OPTIONS
The --clear, --read-clear, --console-on, --console-off, and --console-level options are mutually exclusive.
Example 15: How to check all the options available with dmesg command
If you want to check all the options available with dmesg command then you need to use dmesg --help
command as shown below.
root@cyberithub:~# dmesg --help
Usage:
dmesg [options]
Display or control the kernel ring buffer.
Options:
-C, --clear clear the kernel ring buffer
-c, --read-clear read and clear all messages
-D, --console-off disable printing messages to console
-E, --console-on enable printing messages to console
-F, --file <file> use the file instead of the kernel log buffer
-f, --facility <list> restrict output to defined facilities
-H, --human human readable output
-k, --kernel display kernel messages
-L, --color[=<when>] colorize messages (auto, always or never)
colors are enabled by default
...............................................