How to view Linux boot messages using dmesg command

In this article, we are going to learn how to view Linux boot messages using dmesg command. dmesg in full means driver message. It is used to write kernel messages to the standard output.

How to view Linux boot messages using dmesg command

So, how can you view Linux boot messages using dmesg command in Linux?

Let’s first learn a little bit more about the boot-up process in Linux and the kernel.

The kernel interfaces the physical hardware and the processes running the hardware. It is first loaded into the memory when the computer boots up.

During booting, various messages are generated by the kernel. These messages show the hardware devices and if they can be configured.

The dmesg reads data produced by the ring buffer of the kernel. A ring buffer is a fixed buffer that stores new data while overwriting the oldest data. Reading these messages using the dmesg command can help to troubleshoot problems experienced during the boot process, information about the system and the hardware.

Most of the messages are output by the hardware device drivers and it makes it hard to read many scrolling messages on the screen. This brings us to the advantage of this command as it makes it easier to view the log messages in a controlled manner. It is also easy to use.

On the other hand, the main disadvantage that almost all Linux tools face is that it is not possible to format the output using dmesg command.

Viewing and manipulating boot messages

Most Unix distros store a post-boot copy of the message buffer at /var/log/dmesg . For the purpose of this tutorial, I will be using Ubuntu system.

To start, you can open the terminal and type the following command.

dmseg

Once you enter the command you will see such a sample output;

[    0.000000] Linux version 5.11.0-43-generic (buildd@lcy02-amd64-036) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #47~20.04.2-Ubuntu SMP Mon Dec 13 11:06:56 UTC 2021 (Ubuntu 5.11.0-43.47~20.04.2-generic 5.11.22)
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.11.0-43-generic root=UUID=9ba78fd5-5700-41a3-ae88-a50975fd770c ro find_preseed=/preseed.cfg auto noprompt priority=critical locale=en_US quiet
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Hygon HygonGenuine
[    0.000000]   Centaur CentaurHauls
[    0.000000]   zhaoxin   Shanghai  
[    0.000000] Disabled fast string operations
[    0.000000] x86/fpu: x87 FPU will use FXSAVE
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009e7ff] usable
[    0.000000] BIOS-e820: [mem 0x000000000009e800-0x000000000009ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000000dc000-0x00000000000fffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000bfecffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000bfed0000-0x00000000bfefefff] ACPI data
[    0.000000] BIOS-e820: [mem 0x00000000bfeff000-0x00000000bfefffff] ACPI NVS
[    0.000000] BIOS-e820: [mem 0x00000000bff00000-0x00000000bfffffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000f0000000-0x00000000f7ffffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fec00000-0x00000000fec0ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fee00000-0x00000000fee00fff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fffe0000-0x00000000ffffffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000100000000-0x000000013fffffff] usable
[    0.000000] NX (Execute Disable) protection: active

As stated earlier, the output is long, and hard to get the required information. It is thus crucial to find other tools to read and search for the required information. Such tools as more, less, head, tail, grep are used frequently.

  • more: helps to read extra information that can fit on the screen. For example;
dmesg | more
  • less: can be used to manipulate the behavior of the output such number of lines. e.g
dmesg | less
  • head: print the first specific number lines from the output. 10 lines by default.
dmesg | head

Or to specify the number of lines;

dmesg | head -5
  • tail: print the last specific number lines from the output. 10 lines by default.
dmesg | tail

Or to specify the number of lines;

dmesg | tail -5
  • grep: search for specific keyword within the dmesg log messages. The basic syntax is;
dmesg | grep 'expression_to_search'

For instance, to find the log for USB device, just type as below and press enter

dmesg | grep 'usb'

Sample output;

[    0.289463] usbcore: registered new interface driver usbfs
[    0.289463] usbcore: registered new interface driver hub
[    0.289463] usbcore: registered new device driver usb
[    0.605191] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.04
[    0.605193] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.605194] usb usb1: Product: xHCI Host Controller
[    0.605195] usb usb1: Manufacturer: Linux 5.4.0-48-generic xhci-hcd
[    0.605197] usb usb1: SerialNumber: 0000:00:14.0
[    0.606129] usb usb2: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.04
[    0.606130] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.606131] usb usb2: Product: xHCI Host Controller
[    0.606133] usb usb2: Manufacturer: Linux 5.4.0-48-generic xhci-hcd
[    0.606134] usb usb2: SerialNumber: 0000:00:14.0
[    0.938924] usb 1-6: new high-speed USB device number 2 using xhci_hcd
[    1.091657] usbcore: registered new interface driver usbhid
[    1.091657] usbhid: USB HID core driver
[    1.102237] usb 1-6: New USB device found, idVendor=13d3, idProduct=56b2, bcdDevice=17.11
[    1.102238] usb 1-6: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[    1.102239] usb 1-6: Product: Integrated Camera
[    1.102240] usb 1-6: Manufacturer: SunplusIT Inc
[    1.230838] usb 1-7: new full-speed USB device number 3 using xhci_hcd
[    1.381196] usb 1-7: New USB device found, idVendor=06cb, idProduct=00be, bcdDevice= 0.00
[    1.381196] usb 1-7: New USB device strings: Mfr=0, Product=0, SerialNumber=1
[    1.381197] usb 1-7: SerialNumber: 2b1503723725
[    1.511106] usb 1-10: new full-speed USB device number 4 using xhci_hcd
[    1.661672] usb 1-10: New USB device found, idVendor=8087, idProduct=0aaa, bcdDevice= 0.02
[    1.661674] usb 1-10: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[   36.130507] input: Integrated Camera: Integrated C as /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0/input/input18
[   36.130559] usbcore: registered new interface driver uvcvideo
[   36.251094] usbcore: registered new interface driver btusb
...

To check available memory, just use grep combined with dmesg as shown below an press enter

dmesg | grep -i memory

The output displayed is:

[    0.017042] check: Scanning 1 areas for low memory corruption
[    0.017333] ACPI: Reserving FACP table memory at [mem 0xbfefee73-0xbfefef66]
[    0.017335] ACPI: Reserving DSDT table memory at [mem 0xbfedd9e8-0xbfefee72]
[    0.017336] ACPI: Reserving FACS table memory at [mem 0xbfefffc0-0xbfefffff]
[    0.017337] ACPI: Reserving FACS table memory at [mem 0xbfefffc0-0xbfefffff]
[    0.017338] ACPI: Reserving BOOT table memory at [mem 0xbfedd9c0-0xbfedd9e7]
[    0.017339] ACPI: Reserving APIC table memory at [mem 0xbfedd27e-0xbfedd9bf]
[    0.017340] ACPI: Reserving MCFG table memory at [mem 0xbfedd242-0xbfedd27d]
[    0.017341] ACPI: Reserving SRAT table memory at [mem 0xbfedc72f-0xbfedcffe]
[    0.017342] ACPI: Reserving HPET table memory at [mem 0xbfedc6f7-0xbfedc72e]
[    0.017343] ACPI: Reserving WAET table memory at [mem 0xbfedc6cf-0xbfedc6f6]
[    0.019493] Early memory node ranges

To see the direct memory accessible(DMA) of the hard drive, just use grep combined with dmesg like this and hit enter

dmesg | grep -i dma

The output displayed is:

[    0.019483]   DMA      [mem 0x0000000000001000-0x0000000000ffffff]
[    0.019486]   DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
[    0.019502]   DMA zone: 64 pages used for memmap
[    0.019503]   DMA zone: 21 pages reserved
[    0.019504]   DMA zone: 3997 pages, LIFO batch:0
[    0.019505]   DMA32 zone: 12224 pages used for memmap
[    0.019506]   DMA32 zone: 782288 pages, LIFO batch:63
[    0.019619] On node 0, zone DMA: 1 pages in unavailable ranges
[    0.021958] On node 0, zone DMA: 98 pages in unavailable ranges
[    0.064681] On node 0, zone DMA32: 48 pages in unavailable ranges
[    0.659218] DMA: preallocated 512 KiB GFP_KERNEL pool for atomic allocations
[    0.659255] DMA: preallocated 512 KiB GFP_KERNEL|GFP_DMA pool for atomic allocations
[    0.659255] DMA: preallocated 512 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations
[    3.361533] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[    3.723997] ata1: PATA max UDMA/33 cmd 0x1f0 ctl 0x3f6 bmdma 0x1060 irq 14
[    3.724003] ata2: PATA max UDMA/33 cmd 0x170 ctl 0x376 bmdma 0x1068 irq 15

There is quite a number of command line options you use with dmesg command. Read man dmesg to learn more.

For example;

Print the messages with human readable timestamp

You can print kernel ring buffer messages with human readable timestamp by passing option -T to the dmesg command.

dmesg -T | head
[Fri Jan 14 07:36:03 2022] microcode: microcode updated early to revision 0xea, date = 2021-01-05
[Fri Jan 14 07:36:03 2022] Linux version 5.4.0-48-generic (buildd@lcy01-amd64-010) (gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 (Ubuntu 5.4.0-48.52-generic 5.4.60)
[Fri Jan 14 07:36:03 2022] Command line: BOOT_IMAGE=/vmlinuz-5.4.0-48-generic root=/dev/mapper/vgubuntu-root ro quiet splash vt.handoff=7
[Fri Jan 14 07:36:03 2022] KERNEL supported cpus:
[Fri Jan 14 07:36:03 2022]   Intel GenuineIntel
[Fri Jan 14 07:36:03 2022]   AMD AuthenticAMD
[Fri Jan 14 07:36:03 2022]   Hygon HygonGenuine
[Fri Jan 14 07:36:03 2022]   Centaur CentaurHauls
[Fri Jan 14 07:36:03 2022]   zhaoxin   Shanghai  
[Fri Jan 14 07:36:03 2022] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
...

View the kernel messages in realtime

You can view the messages in realtime using the -w/--follow option;

dmesg -w

If you want, you can combine with other options like;

dmesg -wT

You can also write the output of the dmesg command to the file which can be then analyzed to troubleshoot an issue.

Print messages for Specific Log Level/Priority using dmesg

The supported log levels (priorities):

  • 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

Take for example, therefore, that you want to print error related boot messages, then use the command;

dmesg -l err -T
[Fri Jan 14 07:37:51 2022] nvme 0000:01:00.0: AER: PCIe Bus Error: severity=Corrected, type=Physical Layer, (Receiver ID)
[Fri Jan 14 07:37:51 2022] nvme 0000:01:00.0: AER:   device [15b7:5006] error status/mask=00000001/0000e000
[Fri Jan 14 07:37:51 2022] nvme 0000:01:00.0: AER:    [ 0] RxErr                 
[Fri Jan 14 07:37:58 2022] nvme 0000:01:00.0: AER: PCIe Bus Error: severity=Corrected, type=Physical Layer, (Receiver ID)
[Fri Jan 14 07:37:58 2022] nvme 0000:01:00.0: AER:   device [15b7:5006] error status/mask=00000001/0000e000
[Fri Jan 14 07:37:58 2022] nvme 0000:01:00.0: AER:    [ 0] RxErr                 
[Fri Jan 14 07:38:14 2022] nvme 0000:01:00.0: AER: PCIe Bus Error: severity=Corrected, type=Physical Layer, (Receiver ID)
[Fri Jan 14 07:38:14 2022] nvme 0000:01:00.0: AER:   device [15b7:5006] error status/mask=00000001/0000e000
[Fri Jan 14 07:38:14 2022] nvme 0000:01:00.0: AER:    [ 0] RxErr                 
[Fri Jan 14 07:40:26 2022] nvme 0000:01:00.0: AER: PCIe Bus Error: severity=Corrected, type=Physical Layer, (Receiver ID)
[Fri Jan 14 07:40:26 2022] nvme 0000:01:00.0: AER:   device [15b7:5006] error status/mask=00000001/0000e000
[Fri Jan 14 07:40:26 2022] nvme 0000:01:00.0: AER:    [ 0] RxErr                 
...

To print for more than one level, list the levels in comma separated format;

dmesg -l err,crit

Print messages for Specific Log Facility/Categories;

Dmesg supports such log facilities/categories;

  • 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

To print boot messages related to system deamons;

dmesg -f daemon

You can include timestamp;

dmesg -f daemon -T

Sample output;

[Fri Jan 14 07:36:38 2022] systemd[1]: Inserted module 'autofs4'
[Fri Jan 14 07:36:38 2022] systemd[1]: systemd 245.4-4ubuntu3.14 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid)
[Fri Jan 14 07:36:38 2022] systemd[1]: Detected architecture x86-64.
[Fri Jan 14 07:36:38 2022] systemd[1]: Set hostname to .
[Fri Jan 14 07:36:38 2022] systemd[1]: /etc/systemd/system/[email protected]:8: Unknown key name 'ExecPreStart' in section 'Service', ignoring.
[Fri Jan 14 07:36:38 2022] systemd[1]: Created slice Virtual Machine and Container Slice.
[Fri Jan 14 07:36:38 2022] systemd[1]: Created slice system-modprobe.slice.
[Fri Jan 14 07:36:38 2022] systemd[1]: Created slice system-openvpn\x2dclient.slice.
[Fri Jan 14 07:36:38 2022] systemd[1]: Created slice system-postfix.slice.
[Fri Jan 14 07:36:38 2022] systemd[1]: Created slice Cryptsetup Units Slice.
[Fri Jan 14 07:36:38 2022] systemd[1]: Created slice system-systemd\x2dfsck.slice.
[Fri Jan 14 07:36:38 2022] systemd[1]: Created slice User and Session Slice.
[Fri Jan 14 07:36:38 2022] systemd[1]: Started Forward Password Requests to Wall Directory Watch.
[Fri Jan 14 07:36:38 2022] systemd[1]: Set up automount Arbitrary Executable File Formats File System Automount Point.
[Fri Jan 14 07:36:38 2022] systemd[1]: Reached target Remote File Systems.
...

To print for more than one category, list the categories in comma separated format;

dmesg -f syslog,daemon

Decode facility and level (priority) numbers to human-readable prefixes

It is possible to combine the facility and log level on the dmesg output using the -x option;

dmesg -x | head
kern  :info  : [    0.000000] microcode: microcode updated early to revision 0xea, date = 2021-01-05
kern  :notice: [    0.000000] Linux version 5.4.0-48-generic (buildd@lcy01-amd64-010) (gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 (Ubuntu 5.4.0-48.52-generic 5.4.60)
kern  :info  : [    0.000000] Command line: BOOT_IMAGE=/vmlinuz-5.4.0-48-generic root=/dev/mapper/vgubuntu-root ro quiet splash vt.handoff=7
kern  :info  : [    0.000000] KERNEL supported cpus:
kern  :info  : [    0.000000]   Intel GenuineIntel
kern  :info  : [    0.000000]   AMD AuthenticAMD
kern  :info  : [    0.000000]   Hygon HygonGenuine
kern  :info  : [    0.000000]   Centaur CentaurHauls
kern  :info  : [    0.000000]   zhaoxin   Shanghai  
kern  :info  : [    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'

Writing Messages to a File

It is also possible to extract messages of various log levels from the kernel ring buffer using dmesg command and write them to a file.

Below is an example to output the contents to a file named boot_messag_2022_jan.txt

dmesg > boot_messag_2022_jan.txt

The message will be written to the file named boot_message_2022_jan.txt under the current working directory.

Conclusion

That concludes our guide on how to view Linux boot messages using dmesg command. The few examples covered can help you diagnose bugs/issues encountered by the system during booting.

Read more about how to use dmesg and it command line options on;

man dmesg
dmesg --help

System administrator | Software Developer | DevOps

Leave a Comment