首页 资料 > > 正文

环球时讯:Linux诊断系统故障命令dmesg详解

2023-07-02 10:20:17 来源:嵌入式加油站 分享到:

前言本文讲解诊断系统故障命令dmesg

命令简介

dmesg 命令用于显示系统开机信息,可用于诊断系统故障。


(相关资料图)

内核会将系统开机信息存储在ring buffer中,可以使用dmesg命令来查看,开机信息保存在/var/log/dmesg文件中。

用法

查看帮助dmesg -hUsage:dmesg [options]Display orcontrol 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 use the file instead of the kernel log buffer-f, --facility restrict output to defined facilities-H, --human human readable output-k, --kernel display kernel messages-L, --color[=] colorize messages (auto, always or never) colors are enabled by default-l, --level restrict output to defined levels-n, --console-level set level of messages printed to console-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 buffer size to query the kernel ring buffer-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 show timestamp using the given format: [delta|reltime|ctime|notime|iso]Suspending/resume will make ctime and iso timestamps inaccurate.-h, --help display this help-V, --version display versionSupported log facilities: kern - kernel messages user - random user-level messages mail - mail systemdaemon - system daemons auth - security/authorization messagessyslog - messages generated internally by syslogd lpr - line printer subsystem news - network news subsystemSupported log levels (priorities): emerg - system is unusable alert - action must be taken immediately crit - critical conditions err - error conditions warn - warning conditionsnotice - normal but significant condition info - informational debug - debug-level messagesFor 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] Linuxversion 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] AnalogPMU 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

审核编辑:汤梓红

关键词:

x 广告

临沂市举行首批沂蒙山世界地质公园授牌仪式 带动区域经济社会发展

首夏犹清万物秀,芬芳四溢聚蒙山。为充分发挥沂蒙山世界地质公园世界级金字招牌作用,全力服务激活蒙山旅游战略,大力带动区域经济社会发展

郑州新郑挂牌出让5宗国有建设用地使用权 起始价1.74亿元

5月20日,郑州新郑市公共资源中心披露,以挂牌方式出让5宗国有建设用地使用权。据观点新媒体了解,新郑出(2022)11号(网)地块位于新区万福路

4.2万余名残疾人有了专属辅助器具

市残联辅助器具中心为我提供的这辆轮椅,可以躺可以坐,时间长也不太累。由于交通事故导致高位截瘫,张家口市桥东区重度肢体残疾人边海卧病

大庆航空救援支队张家口驻防队伍圆满完成任务

近日,在跨省驻防460余天,圆满完成北京2022年冬奥会和冬残奥会张家口赛区森林防灭火、应急救援等安保任务后,大庆航空救援支队张家口驻防

张家口宣化区不动产登记中心全面提升登记服务工作效率

在工作人员的指引下,半个小时就办完了,没想到这么方便。近日,在宣化区不动产登记中心,前来办理房屋抵押手续的市民孙淑苗高兴地对记者说

x 广告

Copyright   2015-2022 起点地质网版权所有  备案号:皖ICP备2022009963号-12   联系邮箱: 39 60 29 14 2@qq.com