Troubleshooting Using dmesg Command in Unix and Linux

During system bootup process, kernel gets loaded into the memory and it controls the entire system.

When the system boots up, it prints number of messages on the screen that displays information about the hardware devices that the kernel detects during boot process.

These messages are available in kernel ring buffer and whenever the new message comes the old message gets overwritten. You could see all those messages after the system bootup using the dmesg command.

1. View the Boot Messages

By executing the dmesg command, you can view the hardwares that are detected during bootup process and it’s configuration details. There are lot of useful information displayed in dmesg. Just browse through them line by line and try to understand what it means. Once you have an idea of the kind of messages it displays, you might find it helpful for troubleshooting, when you encounter an issue.

# dmesg | more Bluetooth: L2CAP ver 2.8 eth0: no IPv6 routers present bnx2: eth0 NIC Copper Link is Down usb 1-5.2: USB disconnect, address 5 bnx2: eth0 NIC Copper Link is Up, 100 Mbps full duplex

As we discussed earlier, you can also view hardware information using dmidecode.

2. View Available System Memory

You can also view the available memory from the dmesg messages as shown below.

# dmesg | grep Memory Memory: 57703772k/60817408k available (2011k kernel code, 1004928k reserved, 915k data, 208k init)

3. View Ethernet Link Status (UP/DOWN)

In the example below, dmesg indicates that the eth0 link is in active state during the boot itself.

# dmesg | grep eth eth0: Broadcom NetXtreme II BCM5709 1000Base-T (C0) PCI Express found at mem 96000000, IRQ 169, node addr e4:1f:13:62:ff:58 eth1: Broadcom NetXtreme II BCM5709 1000Base-T (C0) PCI Express found at mem 98000000, IRQ 114, node addr e4:1f:13:62:ff:5a eth0: Link up

4. Change the dmesg Buffer Size in /boot/config- file

Linux allows to you change the default size of the dmesg buffer. The CONFIG_LOG_BUF_SHIFT parameter in the /boot/config-2.6.18-194.el5 file (or similar file on your system) can be changed to modify the dmesg buffer.

The below value is in the power of 2. So, the buffer size in this example would be 262144 bytes. You can modify the buffer size based on your need (SUSE / REDHAT).

# grep CONFIG_LOG_BUF_SHIFT /boot/config-`uname -r` CONFIG_LOG_BUF_SHIFT=18

5. Clear Messages in dmesg Buffer

Sometimes you might want to clear the dmesg messages before your next reboot. You can clear the dmesg buffer as shown below.

# dmesg -c # dmesg

6. dmesg timestamp: Date and Time of Each Boot Message in dmesg

By default the dmesg don’t have the timestamp associated with them. However Linux provides a way to see the date and time for each boot messages in dmesg in the /var/log/kern.log file as shown below.

klogd service should be enabled and configured properly to log the messages in /var/log/kern.log file.

# dmesg | grep "L2 cache" [ 0.014681] CPU: L2 cache: 2048K # grep "L2 cache" kern.log.1 Oct 18 23:55:40 ubuntu kernel: [ 0.014681] CPU: L2 cache: 2048K

If you enjoyed this article, you might also like..