dmesg (Display message or driver message) is a command which will show Kernel ring buffers. These messages contain valuable information about device drivers loaded into the kernel at the time of booting as well as when we connect a hardware to the system on the fly. In other words dmesg will give us details about hardware drivers connected to, disconnected from a machine and any errors when hardware driver is loaded into the kernel. These messages are helpful in diagnosing or debugging hardware and device driver issues. Already covered command in the series is

	Get BIOS, Firmware, Hardware And Drivers Details in Linux/Unix

dmesg command syntax

dmesg options

dmesg output format

	[ time ] device name: message

[ time ] : number seconds from the boot time. If we see something like 34.23445 as time stamp, that indicates this message was created after 34 seconds of booting the machine.

device name: This will give us the hardware device name along with manufacture details.

message: This is actual information we have to look at, this message contain information about devices loaded information, if it's not loaded it will give us error etc.

Learn dmesg with examples

Example 1: Display all the devices drivers loaded in to kernel.


The above command will give as all the hardware drivers loaded in to kernel, their status success or failed and even error message why they are failed.

Example2: Display hardware information related to Ethernet port eth0

	dmesg | grep -i eth0

Clipped Output:

	[ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 3.5.0-25-generic (buildd@komainu) (gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1) ) #39-Ubuntu SMP Mon Feb 25 18:26:58 UTC 2013 (Ubuntu 3.5.0-25.39-generic
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.5.0-25-generic root=UUID=9b1dca12-2bf6-47d3-ab45-929f85bec913 ro quiet splash vt.handoff=7
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Centaur CentaurHauls
[ 0.000000] e820: BIOS-provided physical RAM map:

We can use grep command to filter any kind of information from dmesg command. Know more about grep command here.

To display USB stuff

dmesg | grep -i usb


	[ 0.898683] ACPI: bus type usb registered
[ 0.898700] usbcore: registered new interface driver usbfs
[ 0.898707] usbcore: registered new interface driver hub
[ 0.898725] usbcore: registered new device driver usb
[ 1.057206] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[ 1.057248] ehci_hcd 0000:00:1a.0: new USB bus registered, assigned bus number 1
[ 1.071681] ehci_hcd 0000:00:1a.0: USB 2.0 started, EHCI 1.00
[ 1.071737] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[ 1.071742] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1


To display total memory available and shared memory details

dmesg | grep -i Memory


	[ 0.000000] Memory: 8008776k/9697280k available (6722k kernel code, 1460428k absent, 228076k reserved, 6448k data, 932k init)
[ 0.000000] please try 'cgroup_disable=memory' option if you don't want memory cgroups
[ 0.003319] Initializing cgroup subsys memory
[ 0.497325] Freeing initrd memory: 15664k freed
[ 1.723922] Freeing unused kernel memory: 932k freed
[ 1.727869] Freeing unused kernel memory: 1460k freed
[ 1.730885] Freeing unused kernel memory: 1120k freed

Display if any bluetooth device is present or not

	dmesg | grep -i bluetooth


	[ 27.145978] Bluetooth: Core ver 2.16
[ 27.145998] Bluetooth: HCI device and connection manager initialized
[ 27.146001] Bluetooth: HCI socket layer initialized
[ 27.146003] Bluetooth: L2CAP socket layer initialized
[ 27.146009] Bluetooth: SCO socket layer initialized
[ 41.586902] Bluetooth: RFCOMM TTY layer initialized
[ 41.586909] Bluetooth: RFCOMM socket layer initialized
[ 41.586911] Bluetooth: RFCOMM ver 1.11
[ 42.003041] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[ 42.003045] Bluetooth: BNEP filters: protocol multicast

Display tty information

	dmesg | grep -i tty


	[ 0.000000] console [tty0] enabled
[ 34.210105] usb 2-1.1: GSM modem (1-port) converter now attached to ttyUSB0
[ 34.210198] usb 2-1.1: GSM modem (1-port) converter now attached to ttyUSB1
[ 34.210285] usb 2-1.1: GSM modem (1-port) converter now attached to ttyUSB2
[ 41.586902] Bluetooth: RFCOMM TTY layer initialized
[ 197.980023] option1 ttyUSB0: option_instat_callback: error -108

More interaction with dmesg:

We can clear dmesg logs from dmesg command output if required by using clear switch -c as shown below.

	dmesg -c

Note: This command will clear dmesg logs from boot time to till that time. If you connect any hardware after this command execution, you can see these new messages in dmesg output.

accidentally deleted dmesg messages by running dmesg -c? Dont worry these messages are stored in /var/log/kern.log or /var/log/dmesg files.

Check latest dmesg logs by viewing content of these two files.

	cat /var/log/kern.log


	May 19 06:59:46 linuxnix kernel: [ 3047.124011] atkbd serio0: Unknown key released (translated set 2, code 0xab on isa0060/serio0).
May 19 06:59:46 linuxnix kernel: [ 3047.124015] atkbd serio0: Use 'setkeycodes e02b <keycode>' to make it known.
May 19 06:59:46 linuxnix kernel: [ 3047.382982] atkbd serio0: Unknown key pressed (translated set 2, code 0xab on isa0060/serio0).
May 19 06:59:46 linuxnix kernel: [ 3047.383000] atkbd serio0: Use 'setkeycodes e02b <keycode>' to make it known.


cat /var/log/dmesg


	[ 38.115030] RPC: Registered named UNIX socket transport module.
[ 38.115034] RPC: Registered udp transport module.
[ 38.115036] RPC: Registered tcp transport module.
[ 38.115038] RPC: Registered tcp NFSv4.1 backchannel transport module.
[ 38.186630] FS-Cache: Loaded
[ 38.235731] init: munin-node main process (1082) terminated with status 127
[ 38.235754] init: munin-node main process ended, respawning
[ 38.300708] NFS: Registering the id_resolver key type
[ 38.300724] Key type id_resolver registered
[ 38.300725] Key type id_legacy registered
[ 38.300733] FS-Cache: Netfs 'nfs' registered for caching

One advantage about kern.log file is it will give you system time for each log it created instead of boot time. In our next posts we will see how to use other hardware related commands in detail.