linux dmesg 查看系统故障信息
dmesg 可以查看linux 内核信息
dmesg’命令设备故障的诊断是非常重要的。在‘dmesg’命令的帮助下进行硬件的连接或断开连接操作时,我们可以看到硬件的检测或者断开连接的信息。‘dmesg’命令在多数基于Linux和Unix的操作系统中都可以使用。
1. 列出加载到内核中的所有驱动
我们可以使用如‘more’。 ‘tail’, ‘less ’或者‘grep’文字处理工具来处理‘dmesg’命令的输出。由于dmesg日志的输出不适合在一页中完全显示,因此我们使用管道(pipe)将其输出送到more或者less命令单页显示。
root@cdncenter ~]# dmesg |more
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.10.-693.2..el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.
(Red Hat 4.8.-) (GCC) ) # SMP Tue Sep :: UTC
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.10.-693.2..el7.x86_64 root=UUID=eb448abb--4d8d-bcde-
434d586a31 ro crashkernel=auto net.ifnames= console=tty0 console=ttyS0,115200n8
[ 0.000000] e820: BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000bffdffff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000bffe0000-0x00000000bfffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000100000000-0x000000043fffffff] usable
[ 0.000000] NX (Execute Disable) protection: active
[ 0.000000] SMBIOS 2.8 present.
[ 0.000000] DMI: Alibaba Cloud Alibaba Cloud ECS, BIOS rel-1.7.--ge51488c-20140602_164612-nilsson.home.kraxel.org //
[ 0.000000] Hypervisor detected: KVM
[ 0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[ 0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable
[ 0.000000] e820: last_pfn = 0x440000 max_arch_pfn = 0x400000000
[ 0.000000] MTRR default type: write-back
[ 0.000000] MTRR fixed ranges enabled:
[ 0.000000] -9FFFF write-back
[ 0.000000] A0000-BFFFF uncachable
[ 0.000000] C0000-FFFFF write-protect
[ 0.000000] MTRR variable ranges enabled:
[ 0.000000] base 0000C0000000 mask 3FFFC0000000 uncachable
[ 0.000000] disabled
[ 0.000000] disabled
[ 0.000000] disabled
[ 0.000000] disabled
[ 0.000000] disabled
[ 0.000000] disabled
[ 0.000000] disabled
[ 0.000000] x86 PAT enabled: cpu , old 0x7040600070406, new 0x7010600070106
[ 0.000000] e820: last_pfn = 0xbffe0 max_arch_pfn = 0x400000000
[ 0.000000] found SMP MP-table at [mem 0x000f0e80-0x000f0e8f] mapped at [ffff8800000f0e80]
[ 0.000000] Base memory trampoline at [ffff880000099000] size
[ 0.000000] Using GB pages for direct mapping
[ 0.000000] BRK [0x01fe9000, 0x01fe9fff] PGTABLE
[ 0.000000] BRK [0x01fea000, 0x01feafff] PGTABLE
[ 0.000000] BRK [0x01feb000, 0x01febfff] PGTABLE
[ 0.000000] RAMDISK: [mem 0x35e41000-0x36f18fff]
--More--
dmesg | less
2. 列出所有被检测到的硬件
要显示所有被内核检测到的硬盘设备,你可以使用‘grep’命令搜索‘sda’关键词,如下
dmesg |grep sda
sd :::: [sda] -byte logical blocks: ( GB/ GiB)
sd :::: [sda] Write Protect is off
sd :::: [sda] Mode Sense:
sd :::: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
sda: sda1 sda2 sda3 sda4 < sda5 sda6 sda7 sda8 >
sd :::: [sda] Attached SCSI disk
EXT4-fs (sda5): INFO: recovery required on readonly filesystem
EXT4-fs (sda5): write access will be enabled during recovery
EXT4-fs (sda5): orphan cleanup on readonly fs
EXT4-fs (sda5): ext4_orphan_cleanup: deleting unreferenced inode
EXT4-fs (sda5): ext4_orphan_cleanup: deleting unreferenced inode
EXT4-fs (sda5): ext4_orphan_cleanup: deleting unreferenced inode
EXT4-fs (sda5): ext4_orphan_cleanup: deleting unreferenced inode
EXT4-fs (sda5): ext4_orphan_cleanup: deleting unreferenced inode
EXT4-fs (sda5): ext4_orphan_cleanup: deleting unreferenced inode
EXT4-fs (sda5): ext4_orphan_cleanup: deleting unreferenced inode
EXT4-fs (sda5): ext4_orphan_cleanup: deleting unreferenced inode
EXT4-fs (sda5): ext4_orphan_cleanup: deleting unreferenced inode
EXT4-fs (sda5): ext4_orphan_cleanup: deleting unreferenced inode
EXT4-fs (sda5): ext4_orphan_cleanup: deleting unreferenced inode
EXT4-fs (sda5): orphan inodes deleted
EXT4-fs (sda5): recovery complete
EXT4-fs (sda5): mounted filesystem with ordered data mode. Opts:
dracut: Mounted root filesystem /dev/sda5
EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts:
EXT4-fs (sda8): mounted filesystem with ordered data mode. Opts:
EXT4-fs (sda6): mounted filesystem with ordered data mode. Opts:
EXT4-fs (sda2): mounted filesystem with ordered data mode. Opts:
EXT4-fs (sda3): mounted filesystem with ordered data mode. Opts:
Adding 4095992k swap on /dev/sda7. Priority:- extents: across:4095992k
注解 ‘sda’表示第一块 SATA硬盘,‘sdb’表示第二块SATA硬盘。若想查看IDE硬盘搜索‘hda’或‘hdb’关键词。
3. 只输出dmesg命令的前20行日志
在‘dmesg’命令后跟随‘head’命令来显示开始几行,‘dmesg | head -20′命令将显示开始的前20行
[root@cdncenter ~]# dmesg |head -
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.10.-693.2..el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8. (Red Hat 4.8.-) (GCC) ) # SMP Tue Sep :: UTC
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.10.-693.2..el7.x86_64 root=UUID=eb448abb--4d8d-bcde-94434d586a31 ro crashkernel=auto net.ifnames= console=tty0 console=ttyS0,115200n8
[ 0.000000] e820: BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000bffdffff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000bffe0000-0x00000000bfffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000100000000-0x000000043fffffff] usable
[ 0.000000] NX (Execute Disable) protection: active
[ 0.000000] SMBIOS 2.8 present.
[ 0.000000] DMI: Alibaba Cloud Alibaba Cloud ECS, BIOS rel-1.7.--ge51488c-20140602_164612-nilsson.home.kraxel.org //
[ 0.000000] Hypervisor detected: KVM
[ 0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[ 0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable
4. 只输出dmesg命令最后20行日志
在‘dmesg’命令后跟随‘tail’命令(‘ dmesg | tail -fn20’)来输出‘dmesg’命令的最后20行日志,当你插入可移动设备时它是非常有用的。
[root@cdncenter ~]# dmesg |tail -fn
[ 2.314442] systemd[]: RTC configured in localtime, applying delta of minutes to system time.
[ 2.356464] ip_tables: (C) - Netfilter Core Team
[ 2.357910] systemd[]: Inserted module 'ip_tables'
[ 2.738351] EXT4-fs (vda1): re-mounted. Opts: (null)
[ 2.764522] systemd-journald[]: Received request to flush runtime journal from PID
[ 2.959266] piix4_smbus ::01.3: SMBus Host Controller at 0x700, revision
[ 2.961623] input: PC Speaker as /devices/platform/pcspkr/input/input5
[ 2.997176] ppdev: user-space parallel port driver
[ 3.042041] AES CTR mode by8 optimization enabled
[ 3.046874] alg: No test for __gcm-aes-aesni (__driver-gcm-aes-aesni)
[ 3.055487] alg: No test for crc32 (crc32-pclmul)
[ 3.067561] EDAC MC: Ver: 3.0.
[ 3.099789] type= audit(1532936276.320:): audit_pid= old= auid= ses= res=
[ 25.780005] random: crng init done
[ 143.596270] vdb: vdb1
[ 235.262057] EXT4-fs (vdb1): mounting ext3 file system using the ext4 subsystem
[ 235.266667] EXT4-fs (vdb1): mounted filesystem with ordered data mode. Opts: (null)
[ 7739.681829] nf_conntrack version 0.5. ( buckets, max)
[ 7796.760635] ip_tables: (C) - Netfilter Core Team
[ 7796.772093] nf_conntrack version 0.5. ( buckets, max)
由于‘dmesg’命令的输出实在太长了,在其中搜索某个特定的字符串是非常困难的。因此,有必要过滤出一些包含‘usb’ ‘dma’ ‘tty’ ‘memory’等字符串的日志行。grep 命令 的‘-i’选项表示忽略大小写
[root@cdncenter ~]# dmesg | grep -i memory
[ 0.000000] Base memory trampoline at [ffff880000099000] size
[ 0.000000] Reserving 161MB of memory at 688MB for crashkernel (System RAM: 16383MB)
[ 0.000000] Early memory node ranges
[ 0.000000] PM: Registered nosave memory: [mem 0x0009f000-0x0009ffff]
[ 0.000000] PM: Registered nosave memory: [mem 0x000a0000-0x000effff]
[ 0.000000] PM: Registered nosave memory: [mem 0x000f0000-0x000fffff]
[ 0.000000] PM: Registered nosave memory: [mem 0xbffe0000-0xbfffffff]
[ 0.000000] PM: Registered nosave memory: [mem 0xc0000000-0xfeffbfff]
[ 0.000000] PM: Registered nosave memory: [mem 0xfeffc000-0xfeffffff]
[ 0.000000] PM: Registered nosave memory: [mem 0xff000000-0xfffbffff]
[ 0.000000] PM: Registered nosave memory: [mem 0xfffc0000-0xffffffff]
[ 0.000000] Memory: 4978256k/17825792k available (6886k kernel code, 1049096k absent, 528008k reserved, 4545k data, 1764k init)
[ 0.000000] please try 'cgroup_disable=memory' option if you don't want memory cgroups
[ 0.438460] Initializing cgroup subsys memory
[ 1.113298] Freeing initrd memory: 17248k freed
[ 1.204199] Non-volatile memory driver v1.
[ 1.206865] crash memory driver: version 1.1
[ 1.308053] Freeing unused kernel memory: 1764k freed
[ 1.614633] [TTM] Zone kernel: Available graphics memory: kiB
[ 1.614633] [TTM] Zone dma32: Available graphics memory: kiB
7. 实时监控dmesg日志输出
[root@cdncenter ~]# tail -f /var/log/dmesg
[ 2.738351] EXT4-fs (vda1): re-mounted. Opts: (null)
[ 2.764522] systemd-journald[]: Received request to flush runtime journal from PID
[ 2.959266] piix4_smbus ::01.3: SMBus Host Controller at 0x700, revision
[ 2.961623] input: PC Speaker as /devices/platform/pcspkr/input/input5
[ 2.997176] ppdev: user-space parallel port driver
[ 3.042041] AES CTR mode by8 optimization enabled
[ 3.046874] alg: No test for __gcm-aes-aesni (__driver-gcm-aes-aesni)
[ 3.055487] alg: No test for crc32 (crc32-pclmul)
[ 3.067561] EDAC MC: Ver: 3.0.
[ 3.099789] type= audit(1532936276.320:): audit_pid= old= auid= ses= res=
查看存储在‘/var/log/dmesg’文件中的日志
查看dmesg中的时间
通过dmesg列出的事件时间不易理解,例如:
[19078.666869] EXT4-fs (sdl): warning: maximal mount count reached, running e2fsck is recommended
[19078.723154] EXT4-fs (sdm): warning: maximal mount count reached, running e2fsck is recommended
[19078.913409] EXT4-fs (sdh): warning: maximal mount count reached, running e2fsck is recommended
[69740.690129] Bridge firewalling registered
通过下面命令转换成可读时间:
[root@buffer236017 src]# date -d "1970-01-01 UTC `echo "$(date +%s)-$(cat /proc/uptime|cut -f -d' ')+69740.690129"|bc `seconds"
Fri Aug :: CST
[root@buffer236017 src]#
Linux dmesg输出没有时间列
网上查了半天,发现是系统自带的版本太低,dmesg命令不支时间参数,如果需要输出时间字段,需要重新编译内核,设置下面参数:CONFIG_PRINTK_TIME=y
还有一种变通的方法,利用rsyslog,将kernel日志输出到文件中,修改/etc/[r]syslog.conf,添加如下配置:
kern.* /var/log/kern.log
重启rsyslog守护进程即可,后续可以在 /var/log/kern.log中查看 kernel日志信息。
linux dmesg 查看系统故障信息的更多相关文章
- linux下查看串口信息
rs232串口通信接口:当通信距离较近时(<12m),可以使用电缆线直接连接,若距离较远,需附加调制解调器. 9个脚针的定义: CDC数据载波检测,RXD接收数据,TXD发送数据,DTR数据中断 ...
- Linux下查看CPU信息、机器型号等硬件信息命令
Linux下查看CPU信息.机器型号等硬件信息命令 编写一个bash脚本: vim info.sh #!/bin/bash cat /etc/issue echo "____________ ...
- Linux下 查看CPU信息
参考: Linux和Windows下查看cpu和core个数 Linux下 查看CPU信息 1.查看完整CPU信息: $ cat /proc/cpuinfo 2.查看逻辑cpu个数: $ cat /p ...
- [转]Linux下查看CPU信息、机器型号等硬件信息
From: http://www.jbxue.com/LINUXjishu/14582.html 查看CPU信息(型号) : # cat /proc/cpuinfo | grep name | cut ...
- Linux中查看CPU信息【转】
[转自]:http://blog.chinaunix.net/uid-23622436-id-3311579.html cat /proc/cpuinfo中的信息 processor 逻辑 ...
- Linux中查看CPU信息 (转)
cat /proc/cpuinfo中的信息 processor 逻辑处理器的id. physical id 物理封装的处理器的id. core id 每个核心的id. ...
- Linux下查看硬件信息的方法
用硬件检测程序kuduz探测新硬件:service kudzu start ( or restart) 查看CPU信息:cat /proc/cpuinfo 查看板卡信息:cat /proc/pci 查 ...
- 如何在Linux下查看版本信息
Linux下如何查看版本信息, 包括位数.版本信息以及CPU内核信息.CPU具体型号等等,整个CPU信息一目了然. 1.# uname -a (Linux查看版本当前操作系统内核信息) L ...
- Linux系统查看日志信息总结
命令: cat tail -f #系统日志文件存放路径: /var/log/message #系统启动后的信息和错误日志 /var/log/secure #与安全相关的日志信息 /var/log/ma ...
随机推荐
- Dapper Extensions Change Schema
Dapper Extensions Change Schema You can use the AutoClassMapper to assign a new schema to your model ...
- cordova(安卓)(腾讯信鸽注册绑定与反绑定) 插件开发
腾讯信鸽快速开发指南 http://developer.xg.qq.com/index.php/Android_SDK%E5%BF%AB%E9%80%9F%E6%8C%87%E5%8D%97 本文参考 ...
- VS 2013 未找到与约束contractname Microsoft.VisualStudio.Utilities.IContentTypeRegistryService......匹配的导出
错误信息: 点击解决方案中的文件,就会提示这个错误.最近给vs2013安装了python的插件,安装了vs2017的python,可能是这两个导致了这个错误. 解决方案: 删除 C:\Users\ji ...
- numpy 中不常用的一些方法
作者:代码律动链接:https://zhuanlan.zhihu.com/p/36303821来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 挑战 1:引入 numpy ...
- apache 二级域名设置完整步骤
步骤如下: 1. 你要拥有一个有泛域名解析的顶级域名,例如:abc.com 在dns服务上设置,域名服务商都提供此服务 www.abc.com 指向服务器IPabc.com ...
- 170823、SQL Update多表联合更新的方法
SQL Update多表联合更新的方法 (1) sqlite 多表更新方法 update t1 set col1=t2.col1 from table1 t1 inner join table2 t2 ...
- Python基础爬虫
搭建环境: win10,Python3.6,pycharm,未设虚拟环境 之前写的爬虫并没有架构的思想,且不具备面向对象的特征,现在写一个基础爬虫架构,爬取百度百科,首先介绍一下基础爬虫框架的五大模块 ...
- struts2常用标签详解(申明:来源于网络)
struts2常用标签详解(申明:来源于网络) 地址:http://blessht.iteye.com/blog/1184960
- Understanding Flash: Blocks, Pages and Program / Erases
https://flashdba.com/2014/06/20/understanding-flash-blocks-pages-and-program-erases/ In the last pos ...
- 在moveit编译时找不到manipulation_msgsConfig.cmake manipulation_msgs-config.cmake文件
这是由于少了manipulation_msgs这个包 我们在这里安装这个包就好了 在终端中输入 sudo apt-get install ros-kinetic-manipulation-msgs