前言
本文講解診斷系統故障命令dmesg
命令簡介
dmesg 命令用于顯示系統開機信息,可用于診斷系統故障。
內核會將系統開機信息存儲在ring buffer中,可以使用dmesg命令來查看,開機信息保存在/var/log/dmesg文件中。
用法
查看幫助
dmesg -h
Usage:
dmesg [options]
Display or control the kernel ring buffer.
Options:
-C, --clear? ?? ?? ?? ?? ???clear the kernel ring buffer
-c, --read-clear? ?? ?? ?? ?read and clear all messages
-D, --console-off? ?? ?? ???disable printing messages to console
-E, --console-on? ?? ?? ?? ?enable printing messages to console
-F, --file
-f, --facility ? ?? ? restrict output to defined facilities
-H, --human? ?? ?? ?? ?? ???human readable output
-k, --kernel? ?? ?? ?? ?? ? display kernel messages
-L, --color[=
? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? colors are enabled by default
-l, --level ? ?? ?? ? restrict output to defined levels
-n, --console-level
-P, --nopager? ?? ?? ?? ?? ?do not pipe output into a pager
-p, --force-prefix? ?? ?? ? force timestamp output on each line of multi-line messages
-r, --raw? ?? ?? ?? ?? ?? ? print the raw message buffer
-S, --syslog? ?? ?? ?? ?? ? force to use syslog(2) rather than /dev/kmsg
-s, --buffer-size
-u, --userspace? ?? ?? ?? ? display userspace messages
-w, --follow? ?? ?? ?? ?? ? wait for new messages
-x, --decode? ?? ?? ?? ?? ? decode facility and level to readable string
-d, --show-delta? ?? ?? ?? ?show time delta between printed messages
-e, --reltime? ?? ?? ?? ?? ?show local time and time delta in readable format
-T, --ctime? ?? ?? ?? ?? ???show human-readable timestamp (may be inaccurate!)
-t, --notime? ?? ?? ?? ?? ? don't show any timestamp with messages
? ???--time-format
? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? [delta|reltime|ctime|notime|iso]
Suspending/resume will make ctime and iso timestamps inaccurate.
-h, --help? ?? ?? ?? ?? ?? ?display this help
-V, --version? ?? ?? ?? ?? ?display version
Supported log facilities:
? ? 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
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
For more details see dmesg(1).
命令語法
dmesg [options]
選項說明
-c ?#顯示信息后,清除ring buffer中的內容
-s<緩沖區大小>??#默認值為8196,剛好等于ring buffer的大小
-n ?#設置記錄信息的層級
-D ?#禁用打印消息到控制臺
-E ?#啟用打印消息到控制臺
-h ?#打印幫助文本并退出
-k ?#打印內核消息
-n ?#設置將消息記錄到控制臺的級別
-r ?#打印原始消息緩沖區
-s ?#使用多少大小的緩沖區來查詢內核環緩沖區。默認情況下為16392-T ?#打印人類可讀時間戳
-t ?#不打印內核的時間戳
-u ?#打印用戶空間消息
-V ?#輸出版本信息并退出-
x ?#將設施和級別(優先級)編號解碼為可讀的前綴
應用舉例
在openwrt上查看開機信息
dmesg
[? ? 0.000000] Linux version 5.4.143 (*******) (gcc version 8.4.0 (OpenWrt GCC 8.4.0 r16279-5cc? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???0535800)) #0 Tue Aug 31 2208 2021
[? ? 0.000000] Board has DDR2
[? ? 0.000000] Analog PMU set to hw control
[? ? 0.000000] Digital PMU set to hw control
[? ? 0.000000] SoC Type: MediaTek MT7628AN ver:1 eco:2
[? ? 0.000000] printk: bootconsole [early0] enabled
[? ? 0.000000] CPU0 revision is: 00019655 (MIPS 24KEc)
[? ? 0.000000] MIPS: machine is Jotale JS76x8 (32M)
[? ? 0.000000] Initrd not found or empty - disabling initrd
[? ? 0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[? ? 0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[? ? 0.000000] Zone ranges:
[? ? 0.000000]? ?Normal? ?[mem 0x0000000000000000-0x0000000007ffffff]
[? ? 0.000000] Movable zone start for each node
[? ? 0.000000] Early memory node ranges
[? ? 0.000000]? ?node? ?0: [mem 0x0000000000000000-0x0000000007ffffff]
[? ? 0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff]
[? ? 0.000000] On node 0 totalpages: 32768
[? ? 0.000000]? ?Normal zone: 288 pages used for memmap
[? ? 0.000000]? ?Normal zone: 0 pages reserved
[? ? 0.000000]? ?Normal zone: 32768 pages, LIFO batch:7
[? ? 0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[? ? 0.000000] pcpu-alloc: [0] 0
[? ? 0.000000] Built 1 zonelists, mobility grouping on.??Total pages: 32480
[? ? 0.000000] Kernel command line: console=ttyS0,115200 rootfstype=squashfs,jffs2
[? ? 0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)
[? ? 0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
[? ? 0.000000] Writing ErrCtl register=00000000
[? ? 0.000000] Readback ErrCtl register=00000000
[? ? 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
*******
[? ?11.641746] usbcore: registered new interface driver cdc_subset
[? ?11.689505] PPP generic driver version 2.4.2
[? ?11.703356] usbcore: registered new interface driver qmi_wwan
[? ?11.730537] rndis_host 1-1:1.0 eth1: register 'rndis_host' at usb-101c0000.ehci-1, RNDIS device, ac:4? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???bb9e5
[? ?11.741397] usbcore: registered new interface driver rndis_host
[? ?11.789009] kmodloader: done loading kernel modules from /etc/modules.d/*
[? ?11.855712] urngd: v1.0.2 started.
[? ?12.515084] random: crng init done
[? ?12.518593] random: 1 urandom warning(s) missed due to ratelimiting
[? ?19.978363] rt3050-esw 10110000.esw: link changed 0x00
[? ?22.202128] br-lan: port 1(eth0.1) entered blocking state
[? ?22.207696] br-lan: port 1(eth0.1) entered disabled state
[? ?22.213547] device eth0.1 entered promiscuous mode
[? ?22.218473] device eth0 entered promiscuous mode
[? ?22.255696] br-lan: port 1(eth0.1) entered blocking state
[? ?22.261264] br-lan: port 1(eth0.1) entered forwarding state
[? ?23.004559] rt3050-esw 10110000.esw: link changed 0x01
這樣打印信息不方便查找關鍵信息
查看前25行開機信息
dmesg | head -n 25
[? ? 0.000000] Linux version 5.4.143 (fan@FAN-THINK-PC) (gcc version 8.4.0 (OpenWrt GCC 8.4.0 r16279-5cc0535800)) #0 Tue Aug 31 2208 2021
[? ? 0.000000] Board has DDR2
[? ? 0.000000] Analog PMU set to hw control
[? ? 0.000000] Digital PMU set to hw control
[? ? 0.000000] SoC Type: MediaTek MT7628AN ver:1 eco:2
[? ? 0.000000] printk: bootconsole [early0] enabled
[? ? 0.000000] CPU0 revision is: 00019655 (MIPS 24KEc)
[? ? 0.000000] MIPS: machine is Jotale JS76x8 (32M)
[? ? 0.000000] Initrd not found or empty - disabling initrd
[? ? 0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[? ? 0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[? ? 0.000000] Zone ranges:
[? ? 0.000000]? ?Normal? ?[mem 0x0000000000000000-0x0000000007ffffff]
[? ? 0.000000] Movable zone start for each node
[? ? 0.000000] Early memory node ranges
[? ? 0.000000]? ?node? ?0: [mem 0x0000000000000000-0x0000000007ffffff]
[? ? 0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff]
[? ? 0.000000] On node 0 totalpages: 32768
[? ? 0.000000]? ?Normal zone: 288 pages used for memmap
[? ? 0.000000]? ?Normal zone: 0 pages reserved
[? ? 0.000000]? ?Normal zone: 32768 pages, LIFO batch:7
[? ? 0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[? ? 0.000000] pcpu-alloc: [0] 0
[? ? 0.000000] Built 1 zonelists, mobility grouping on.??Total pages: 32480
[? ? 0.000000] Kernel command line: console=ttyS0,115200 rootfstype=squashfs,jffs2
查看后25行開機信息
dmesg | tail -n 25
[? ?11.352236] GACT probability on
[? ?11.361732] Mirror/redirect action on
[? ?11.395872] u32 classifier
[? ?11.398710]? ???input device check on
[? ?11.402442]? ???Actions configured
[? ?11.463279] usbcore: registered new interface driver cdc_wdm
[? ?11.613359] xt_time: kernel timezone is -0000
[? ?11.626466] usbcore: registered new interface driver cdc_ether
[? ?11.641746] usbcore: registered new interface driver cdc_subset
[? ?11.689505] PPP generic driver version 2.4.2
[? ?11.703356] usbcore: registered new interface driver qmi_wwan
[? ?11.730537] rndis_host 1-1:1.0 eth1: register 'rndis_host' at usb-101c0000.ehci-1, RNDIS device, acb3eb:e5
[? ?11.741397] usbcore: registered new interface driver rndis_host
[? ?11.789009] kmodloader: done loading kernel modules from /etc/modules.d/*
[? ?11.855712] urngd: v1.0.2 started.
[? ?12.515084] random: crng init done
[? ?12.518593] random: 1 urandom warning(s) missed due to ratelimiting
[? ?19.978363] rt3050-esw 10110000.esw: link changed 0x00
[? ?22.202128] br-lan: port 1(eth0.1) entered blocking state
[? ?22.207696] br-lan: port 1(eth0.1) entered disabled state
[? ?22.213547] device eth0.1 entered promiscuous mode
[? ?22.218473] device eth0 entered promiscuous mode
[? ?22.255696] br-lan: port 1(eth0.1) entered blocking state
[? ?22.261264] br-lan: port 1(eth0.1) entered forwarding state
[? ?23.004559] rt3050-esw 10110000.esw: link changed 0x01
查看與內存相關的開機信息
dmesg | grep -i memory
[? ? 0.000000] Early memory node ranges
[? ? 0.000000] Memory: 122688K/131072K available (4436K kernel code, 192K rwdata, 1016K rodata, 1192K init, 193K bss, 8384K reserved, 0K cma-reserved)
[? ? 0.526438] Freeing unused kernel memory: 1192K
[? ? 0.531064] This architecture does not have kernel memory protection.
查看與USB相關的開機信息
dmesg | grep -i usb
[? ? 1.884358] usbcore: registered new interface driver usbfs
[? ? 1.890096] usbcore: registered new interface driver hub
[? ? 1.895617] usbcore: registered new device driver usb
[? ? 1.907868] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[? ? 1.939711] phy phy-10120000.usbphy.0: remote usb device wakeup disabled
[? ? 1.946525] phy phy-10120000.usbphy.0: UTMI 16bit 30MHz
[? ? 1.957713] ehci-platform 101c0000.ehci: new USB bus registered, assigned bus number 1
[? ? 1.984466] ehci-platform 101c0000.ehci: USB 2.0 started, EHCI 1.00
[? ? 1.991901] hub 1-0 USB hub found
[? ? 4.628468] usb 1-1: new high-speed USB device number 2 using ehci-platform
[? ?11.463279] usbcore: registered new interface driver cdc_wdm
[? ?11.626466] usbcore: registered new interface driver cdc_ether
[? ?11.641746] usbcore: registered new interface driver cdc_subset
[? ?11.703356] usbcore: registered new interface driver qmi_wwan
[? ?11.730537] rndis_host 1-1:1.0 eth1: register 'rndis_host' at usb-101c0000.ehci-1, RNDIS device, acb3eb:e5
[? ?11.741397] usbcore: registered new interface driver rndis_host
審核編輯:湯梓紅
評論
查看更多