dmesg Command

dmesg is a command found in all Unix-like OSes commonly used for the purpose of getting information and troubleshooting hardware.

More technically, dmesg is used to explore and control Kernel Ring Buffer where all the kernel related messages such as drivers loaded during booting, detected peripherals and their details are recorded.
The default action of the dmesg is to print the content of the Kernel Ring Buffer.

1. Print all the drivers loaded
The output of the dmesg command runs over a page and need to be piped with more or less command for a page-wise output.

root@kali:~# dmesg | more
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.14-kali1-amd64 ( (gcc version 4.7.2 (Debian 4.7.2-5) ) #1 SM
P Debian 3.14.5-1kali1 (2014-06-07)
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.14-kali1-amd64 root=UUID=36a91284-b11d-4f6f-9f07-9425bc4678ee ro i
nitrd=/install/initrd.gz quiet

2. Search for a specific device class
Using grep the dmesg output can be filtered to obtain specific device information.

root@kali:~# dmesg | grep -i memory
[ 0.000000] Base memory trampoline at [ffff880000099000] 99000 size 24576
[ 0.000000] init_memory_mapping: [mem 0x00000000-0x000fffff]
[ 0.000000] init_memory_mapping: [mem 0xbfc00000-0xbfdfffff]
[ 0.000000] init_memory_mapping: [mem 0xbc000000-0xbfbfffff]
[ 0.000000] init_memory_mapping: [mem 0x80000000-0xbbffffff]
[ 0.000000] init_memory_mapping: [mem 0x00100000-0x7fffffff]
[ 0.000000] init_memory_mapping: [mem 0xbfe00000-0xbffeffff]

root@kali:~# dmesg | grep -i usb
[ 0.465701] ACPI: bus type USB registered
[ 0.465721] usbcore: registered new interface driver usbfs
[ 0.465728] usbcore: registered new interface driver hub
[ 0.478603] usbcore: registered new device driver usb

root@kali:~# dmesg | grep -i tty
[ 0.000000] console [tty0] enabled
[ 0.376782] 00:04: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A

root@kali:~# dmesg | grep -i pci
[ 0.000000] e820: [mem 0xc0000000-0xfffbffff] available for PCI devices
[ 0.072000] ACPI: bus type PCI registered
[ 0.072000] acpiphp: ACPI Hot Plug PCI Controller Driver version: 0.5
[ 0.072000] PCI: Using configuration type 1 for base access

The -i is to ignore the case of the search pattern.

3. Real-time dmesg output
The dmesg log file /var/log/dmesg gets populated with the Kernel Ring Buffer data. Using the follow switch of the tail command the real-time updates of the dmesg log file can be displayed as follows:

root@kali:~# tail -f /var/log/dmesg
[ 9.692301] intel8x0: measured clock 138861 rejected
[ 9.692304] intel8x0: clocking to 48000
[ 11.376204] floppy0: no floppy controllers found
[ 11.376278] work still pending
[ 12.081918] Adding 731132k swap on /dev/sda5. Priority:-1 extents:1 across:731132k
[ 12.089951] EXT4-fs (sda1): re-mounted. Opts: (null)
[ 12.228001] EXT4-fs (sda1): re-mounted. Opts: errors=remount-ro
[ 12.430841] loop: module loaded
[ 13.485671] e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
[ 31.712439] Netfilter messages via NETLINK v0.30.

To break the command use Ctrl+C.

If “tail -f” is not available, the watch command can be used to get the real-time output of dmesg as shown below:

root@kali:~# watch "tail -20 /var/log/dmesg"

The above command displays the last 20 lines of /var/log/dmesg file  and updates every 2 seconds.

4. Clear the Kernel Ring Buffer
Using the -c switch the Kernel Ring Buffer can be cleared. However, the data can still be read from the /var/log/dmesg file.

root@kali:~# dmesg -c

5. Copy and share the dmesg output
The dmesg output is often required to troubleshoot hardware issues. It’s a good idea to keep a copy of the dmesg output for later analysis or for sharing via email.

root@kali# dmesg > kernelmesg.txt

About Deepak Devanand

Seeker of knowledge
This entry was posted in Linux and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s