[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedMarch 14, 2023

How to use dmesg command

How To Use Dmesg Command

In this tutorial, we’ll cover the basics of the dmesg command.

The Linux kernel is the core of the operating system that controls access to the system resources, such as CPU, I/O devices, physical memory, and file systems. The kernel writes various messages to the kernel ring buffer during the boot process, and when the system is running. These messages include various information about the operation of the system.

The kernel ring buffer is a portion of the physical memory that holds the kernel’s log messages. It has a fixed size, which means once the buffer is full, the older logs records are overwritten.

The dmesg command-line utility is used to print and control the kernel ring buffer in Linux and other Unix-like operating systems. It is useful for examining kernel boot messages and debugging hardware related issues.

 

Using the dmesg Command

The syntax for the dmesg command is as follows:

dmesg [OPTIONS]

When invoked without any options dmesg writes all messages from the kernel ring buffer to the standard output:

dmesg

By default, all users can run the dmesg command. However, on some systems, the access to dmesg may be restricted for non-root users. In this situation, when invoking dmesg you will get an error message like below:

dmesg: read kernel buffer failed: Operation not permitted

The kernel parameter kernel.dmesg_restrict specifies whether unprivileged users can use dmesg to view messages from the kernel’s log buffer. To remove the restrictions, set it to zero:

sudo sysctl -w kernel.dmesg_restrict=0

Usually, the output contains a lot of lines of information, so only the last part of the output is viewable. To see one page at a time, pipe the output to a pager utility such as less or more:

dmesg --color=always | less

The –color=always is used to preserve the colored output.

If you want to filter the buffer messages, use grep . For example, to view only the USB related messages, you would type:

dmesg | grep -i usb

dmesg reads the messages generated by the kernel from the /proc/kmsg virtual file. This file provides an interface to the kernel ring buffer and can be opened only by one process. If syslog process is running on your system and you try to read the file with cat , or less, the command will hang.

The syslog daemon dumps kernel messages to /var/log/dmesg, so you can also use that log file:

cat /var/log/dmesg

 

Formating dmesg Output

The dmesg command provides a number of options that help you format and filter the output.

One of the most used options of dmesg is -H (–human), which enables the human-readable output. This option pipe the command output into a pager:

dmesg -H

To print human-readable timestamps use the -T (–ctime) option:

dmesg -T
[Mon Oct 14 14:38:04 2019] IPv6: ADDRCONF(NETDEV_CHANGE): wlp1s0: link becomes ready

The timestamps format can also be set using the –time-format <format> option, which can be ctime, reltime, delta, notime, or iso. For example to use the delta format you would type:

dmesg --time-format=delta

You can also combine two or more options:

dmesg -H -T

To watch the output of the dmesg command in real-time use the -w (–follow) option:

dmesg --follow

 

Filtering dmesg Output

You can restrict the dmesg output to given facilities and levels.

The facility represents the process that created the message. dmesg supports the following log facilities:

  • kern – kernel messages

  • user – user-level messages

  • mail – mail system

  • daemon – system daemons

  • auth – security/authorization messages

  • syslog – internal syslogd messages

  • lpr – line printer subsystem

  • news – network news subsystem

The -f (–facility <list>) option allows you to limit the output to specific facilities. The option accepts one or more comma-separated facilities.

For example, to display only the kernel and system daemons messages you would use:

dmesg -f kern,daemon

Each log message is associated with a log level that shows the importance of the message. dmesg supports the following log levels:

  • emerg – system is unusable

  • alert – action must be taken immediately

  • crit – critical conditions

  • err – error conditions

  • warn – warning conditions

  • notice – normal but significant condition

  • info – informational

  • debug – debug-level messages

The -l (–level <list>) option restricts the output to defined levels. The option accepts one or more comma-separated levels.

The following command displays only the error and critical messages:

dmesg -l err,crit

 

Clearing the Ring Buffer

The -C (–clear) option allows you to clear the ring buffer:

sudo dmesg -C

Only root or users with sudo privileges can clear the buffer.

To print the buffer contents before clearing use the -c (–read-clear) option:

sudo dmesg -c

If you want to save the current dmesg logs in a file before clearing it, redirect the output to a file:

dmesg > dmesg_messages

 

Conclusion

The dmesg command allows you to view and control the kernel ring buffer. It can be very useful when troubleshooting kernel or hardware issues.

Keep reading
How to understand what is SolusVM?
August 31, 2023

How to understand what is SolusVM?

How To Understand What Is SolusVM? SolusVM is a software that allows users to create virtual private servers for their clients. It includes various features that allow users to build a virtual private server (VPS)-based business without having knowledge of programming languages. Key features…

Read article
How to install OpenVZ on Ubuntu 20.4
August 31, 2023

How to install OpenVZ on Ubuntu 20.4

How To Install OpenVZ On Ubuntu 20.4 1. Add OpenVZ Repository Switch to root user: sudo su First, we will add OpenVZ Repository. cat &lt;&lt; EOF &gt; /etc/apt/sources.list.d/openvz-rhel6.list deb http://download.openvz.org/debian wheezy main # deb http://download.openvz.org/debian wheezy-test…

Read article
How to install Xen virtualization on ubuntu20.
August 28, 2023

How to install Xen virtualization on ubuntu20.

How To Install Xen Virtualization On Ubuntu20. Installing Xen on Ubuntu 20.04 involves several steps, including setting up the necessary packages and configuring your system. Xen is a hypervisor that allows you to run multiple virtual machines on a single host system. Here’s a basic guide to help…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00