Linux dmesg Command - Print Kernel Ring Buffer

Dmesg command prints the message buffer of the kernel. Dmesg command is mainly used to identify the failed devices, hot-plugged devices such as USB, I/O devices errors.

When the system boots device drivers present in kernel setup with relevant hardware devices. At that time drivers and other elements with kernel produces messages. These messages are stored in a small buffer space and overwritten each when new messages come. Most Linux distributions store these messages at /var/log/dmesg. Dmesg read directly from kernel ring buffer, not from /var/log/dmesg. Syslog by default (depend on Linux distributions) or configured to capture messages.

Dmesg stores kernel messages during the boot and after booting. After boot, occasionally kernel produces messages when there are io errors, devices plugged in, etc. Those are messages are sent to the system console as well. Dmesg output is often large, can be filtered using more, tail or grep commands.

How to Use dmesg Command

Dmesg command by default print N number of messages from kernel ring buffer.

$ dmesg

Sample output:

[    1.230638] kernel: Run /init as init process
 [    1.336492] kernel: scsi host0: Virtio SCSI HBA
 [    1.338612] kernel: scsi 0:0:0:0: Direct-Access     QEMU     QEMU HARDDISK    2.5+ PQ: 0 ANSI: 5
 [    1.338727] kernel: input: VirtualPS/2 VMware VMMouse as /devices/platform/i8042/serio1/input/input4
 [    1.342266] kernel: input: VirtualPS/2 VMware VMMouse as /devices/platform/i8042/serio1/input/input3
 [    1.345242] kernel: lpc_ich 0000:00:1f.0: I/O space for GPIO uninitialized
 [    1.346920] kernel: ahci 0000:00:1f.2: version 3.0
 [    1.350864] kernel: scsi host1: Virtio SCSI HBA
 [    1.358377] kernel: scsi host2: Virtio SCSI HBA
 [    1.359317] kernel: PCI Interrupt Link [GSIA] enabled at IRQ 16
 [    1.359718] kernel: scsi 1:0:1:2: Direct-Access     QEMU     QEMU HARDDISK    2.5+ PQ: 0 ANSI: 5
 [    1.361478] kernel: ahci 0000:00:1f.2: AHCI 0001.0000 32 slots 6 ports 1.5 Gbps 0x3f impl SATA mode
 [    1.363039] kernel: i801_smbus 0000:00:1f.3: SMBus using PCI interrupt

Dmesg output is mainly divided into 3 parts:

  • Time: Show you number of seconds from the boot time. If you find 20.091730. It is mean the message is created 20 seconds after boot time.
  • Device_name: Show the device name
  • Messages: The actual message. From here, we can analyze what was happen.

1) How to read dmesg

Dmesg command without any options produces a large output. To make it easier to read, use grep or less command to filter the output. Let's check some examples.

Print dmesg output per page

$ dmesg | less

Sample output:

[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 3.8.0-31-generic (buildd@aatxe) (gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1) ) #46-Ubuntu SMP Tue Sep 10 19:56:49 UTC 2013 (Ubuntu 3.8.0-31.46-generic 3.8.13.8)
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] NSC Geode by NSC
[ 0.000000] Cyrix CyrixInstead
[ 0.000000] Centaur CentaurHauls
[ 0.000000] Transmeta GenuineTMx86
[ 0.000000] Transmeta TransmetaCPU
[ 0.000000] UMC UMC UMC UMC

Print information related to eth

$ dmesg | grep eth

Sample output:

[ 1.972418] e1000 0000:00:03.0 eth0: (PCI:33MHz:32-bit) 08:00:27:d2:c1:16
[ 1.972430] e1000 0000:00:03.0 eth0: Intel(R) PRO/1000 Network Connection
[ 18.867656] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 21.733138] e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
[ 21.737967] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 21.738052] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready

Print information related to USB

$ dmesg | grep usb

Sample output:

[ 0.131874] ACPI: bus type usb registered
[ 0.131910] usbcore: registered new interface driver usbfs
[ 0.131921] usbcore: registered new interface driver hub
[ 0.131955] usbcore: registered new device driver usb
[ 1.091722] usb usb1: New USB device found, idVendor=1d6b, idProduct=0001
[ 1.091727] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 1.091730] usb usb1: Product: OHCI Host Controller
[ 1.091731] usb usb1: Manufacturer: Linux 3.8.0-31-generic ohci_hcd
[ 1.091733] usb usb1: SerialNumber: 0000:00:06.0

Please notice that grep command is case-sensitive. ie from the above example "usb" and "USB" give different results. To ignore case-sensitive feature, use -i parameter after grep command. Compare this command output with USB case above.

$ dmesg | grep -i usb

Sample output:

[ 0.131874] ACPI: bus type usb registered
[ 0.131910] usbcore: registered new interface driver usbfs
[ 0.131921] usbcore: registered new interface driver hub
[ 0.131955] usbcore: registered new device driver usb
[ 0.997759] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[ 0.997783] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[ 0.997929] ohci_hcd 0000:00:06.0: new USB bus registered, assigned bus number 1
[ 1.091722] usb usb1: New USB device found, idVendor=1d6b, idProduct=0001
[ 1.091727] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 1.091730] usb usb1: Product: OHCI Host Controller
[ 1.091731] usb usb1: Manufacturer: Linux 3.8.0-31-generic ohci_hcd
[ 1.091733] usb usb1: SerialNumber: 0000:00:06.0
[ 1.091856] hub 1-0:1.0: USB hub found
[ 1.093110] uhci_hcd: USB Universal Host Controller Interface driver

Displaying desired output using head/tail

For example, you have inserted a removable device or made changes to any disk volumes. To check the latest entries of dmesg by using the tail command.

To display the last N lines of the dmesg log:

$ dmesg | tail -15

Similarly, to find the first few lines from dmesg log use the head command. This will be useful to find the changes that happened just after booting up.

$ dmesg | head -15

Real time monitoring

For real time continuous monitoring use the option -f.

$ tail -f /var/log/dmesg

Alternative, use watch dmesg:

$ watch "dmesg | tail -15"

Some Linux system supports using dmesg -w, that will waits for new messages.

2) Print in human readable format

To print dmesg output in a human readable format, use option -H.

$ dmesg -H

3) Convert timestamp to custom date format

By default, the timestamp from dmesg output is not human readable. To change timestamp to custom date format use option - -ctime or -T.

$ dmesg  - -ctime

Sample output :

[Tue Dec 10 16:34:33 2013] 131MB HIGHMEM available.
[Tue Dec 10 16:34:33 2013] 891MB LOWMEM available.
[Tue Dec 10 16:34:33 2013] mapped low ram: 0 - 37bfe000
[Tue Dec 10 16:34:33 2013] low ram: 0 - 37bfe000
[Tue Dec 10 16:34:33 2013] Zone ranges:
[Tue Dec 10 16:34:33 2013] DMA [mem 0x00010000-0x00ffffff]
[Tue Dec 10 16:34:33 2013] Normal [mem 0x01000000-0x37bfdfff]
[Tue Dec 10 16:34:33 2013] HighMem [mem 0x37bfe000-0x3ffeffff]
[Tue Dec 10 16:34:33 2013] Movable zone start for each node
[Tue Dec 10 16:34:33 2013] Early memory node ranges
[Tue Dec 10 16:34:33 2013] node 0: [mem 0x00010000-0x0009efff]
[Tue Dec 10 16:34:33 2013] node 0: [mem 0x00100000-0x3ffeffff

You can also use --time-format <format> to print timestamps using the given format, which can be ctime, reltime, delta or iso.

If timestamp is not enabled then dmesg command may not show timestamp in the output.

To check timestamps is enabled or not, open the file /sys/module/printk/parameters/time:

$ cat /sys/module/printk/parameters/time
N

If the content of the file is N, then timestamp is not enabled. You can run the following command to enable timestamp:

$ echo Y > /sys/module/printk/parameters/time

4) Clear dmesg

To clear messages from kernel ring buffer use option -C.

$ dmesg -C

To clear the ring buffer after printing its contents use option -c.

$ dmesg -c

Even If you clear dmesg using -c or -C parameters, you can still view the logs in /var/log/kern.log or /var/log/dmesg.

5) Stop Dmesg from logging to console

To disable printing of messages to the console use option -D.

$ dmesg -D

Alternative option is to use -n 1 to prevents all messages, except emergency (panic) messages, from appearing on the console.

To enable printing messages to the console use -E.

$ dmesg -E

6) Display messages specific to facility

To print messages from a specific category or facility. To fulfill this purpose, use the option --facility.

From example to print message specific to mail, type:

$ dmesg --facility=daemon

Supported log facilities are:

kern - kernel messages
user - random user-level messages
mail - mail system
daemon - system daemons
auth - security/authorization messages
syslog - messages generated internally by syslogd
lpr - line printer subsystem
news - network news subsystem

7) Print log level

To print messages specific to log level use the option --level. For example to print all warning message run the following command:

$ dmesg --level=warn

Sample output:

[ 0.000000] tsc: Fast TSC calibration failed
[ 19.595760] piix4_smbus 0000:00:07.0: SMBus base address uninitialized - upgrade BIOS or use force_addr=0xaddr

Supported log levels are:

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

8) Display facility and level in human readable

To print facility and log level in a human readable format use the option -x.

$ dmesg -x

Sample output:

kern :debug : [ 0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable
kern :info : [ 0.000000] e820: last_pfn = 0x3fff0 max_arch_pfn = 0x1000000
kern :debug : [ 0.000000] MTRR default type: uncachable
kern :debug : [ 0.000000] MTRR variable ranges disabled:
kern :info : [ 0.000000] x86 PAT enabled: cpu 0, old 0x7040600070406, new 0x7010600070106
kern :info : [ 0.000000] CPU MTRRs all blank - virtualized system.

9) Print kernel message

To print kernel specific messages use the option -k.

$ dmesg -k

10) Ignore timestamp

If you don’t want print the kernel timestamp, use the option -t.

$ dmesg -t

Conclusion

Dmesg can be very useful for diagnosing problems related to the system. In this tutorial, we learned how to use dmesg command in Linux.

2 Comments... add one

Leave a Comment