dmesg 可以查看linux 内核信息

dmesg’命令设备故障的诊断是非常重要的。在‘dmesg’命令的帮助下进行硬件的连接或断开连接操作时,我们可以看到硬件的检测或者断开连接的信息。‘dmesg’命令在多数基于LinuxUnix的操作系统中都可以使用。

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 查看系统故障信息的更多相关文章

  1. linux下查看串口信息

    rs232串口通信接口:当通信距离较近时(<12m),可以使用电缆线直接连接,若距离较远,需附加调制解调器. 9个脚针的定义: CDC数据载波检测,RXD接收数据,TXD发送数据,DTR数据中断 ...

  2. Linux下查看CPU信息、机器型号等硬件信息命令

    Linux下查看CPU信息.机器型号等硬件信息命令 编写一个bash脚本: vim info.sh #!/bin/bash cat /etc/issue echo "____________ ...

  3. Linux下 查看CPU信息

    参考: Linux和Windows下查看cpu和core个数 Linux下 查看CPU信息 1.查看完整CPU信息: $ cat /proc/cpuinfo 2.查看逻辑cpu个数: $ cat /p ...

  4. [转]Linux下查看CPU信息、机器型号等硬件信息

    From: http://www.jbxue.com/LINUXjishu/14582.html 查看CPU信息(型号) : # cat /proc/cpuinfo | grep name | cut ...

  5. Linux中查看CPU信息【转】

    [转自]:http://blog.chinaunix.net/uid-23622436-id-3311579.html cat /proc/cpuinfo中的信息 processor       逻辑 ...

  6. Linux中查看CPU信息 (转)

    cat /proc/cpuinfo中的信息 processor       逻辑处理器的id. physical id    物理封装的处理器的id. core id        每个核心的id. ...

  7. Linux下查看硬件信息的方法

    用硬件检测程序kuduz探测新硬件:service kudzu start ( or restart) 查看CPU信息:cat /proc/cpuinfo 查看板卡信息:cat /proc/pci 查 ...

  8. 如何在Linux下查看版本信息

    Linux下如何查看版本信息, 包括位数.版本信息以及CPU内核信息.CPU具体型号等等,整个CPU信息一目了然.   1.# uname -a   (Linux查看版本当前操作系统内核信息)   L ...

  9. Linux系统查看日志信息总结

    命令: cat tail -f #系统日志文件存放路径: /var/log/message #系统启动后的信息和错误日志 /var/log/secure #与安全相关的日志信息 /var/log/ma ...

随机推荐

  1. 【转帖】解决远程连接MariaDB(mysql)很慢的方法

    在CentOS7上安装完成MariaDB之后,发现无论命令行还是程序中连接MariaDB的时候都很慢,大约要一二十秒,于是网上搜索了一番,发现下面的文章内容: 在进行 ping和route后发现网络通 ...

  2. [Object Tracking] Overview of Object Tracking

    From: 目标跟踪方法的发展概述 From: 目标跟踪领域进展报告 通用目标的跟踪 经典目标跟踪方法 2010 年以前,目标跟踪领域大部分采用一些经典的跟踪方法,比如 Meanshift.Parti ...

  3. [CNN] Understanding Convolution

    From: http://blog.csdn.net/zouxy09/article/details/49080029 一个概念需经过反复的推敲以及时间的沉淀,之后才能真正理解 [OpenCV] Im ...

  4. [转]linux 调用动态库so文件

    记录一个面试被问到的问题. extern 有什么用途? 除了多文件共享全局变量外还有呢? extern "C" 的功能? 我想看完这篇文章就可以知道第三个问题了. 关于动态调用动态 ...

  5. Scala中的协变,逆变,上界,下界等

    Scala中的协变,逆变,上界,下界等 目录 [−] Java中的协变和逆变 Scala的协变 Scala的逆变 下界lower bounds 上界upper bounds 综合协变,逆变,上界,下界 ...

  6. HRMS文件解析2

    returntablefieldColorFilterGray()函数在/lib/select_menu.php文件中,函数如下: function returntablefieldColorFilt ...

  7. H5网页适配 iPhoneX,就是这么简单(转)

    iPhoneX 取消了物理按键,改成底部小黑条,这一改动导致网页出现了比较尴尬的屏幕适配问题.对于网页而言,顶部(刘海部位)的适配问题浏览器已经做了处理,所以我们只需要关注底部与小黑条的适配问题即可( ...

  8. Ext.form.field.Picker (ComboBox、Date、TreePicker、colorpick.Field)竖向滚动导致布局错误

    ComboBox.Date.TreePicker.colorpick.Field这些继承了Ext.form.field.Picker的控件. 在6.0.0和6.0.1中,在界面中存在竖向滚动条时,点击 ...

  9. mui---父页面跳子页面刷新子页面

    最近在做项目,遇到一个问题,从父页面跳转到子页面,不会刷新子页面的问题. 解决方法:可以在跳转的时候,使用openWindow来进行跳转,接下来配置跳转打开页面的参数: 具体如下: mui.openW ...

  10. windows 开启热点的命令行工具

    hotspot.bat @echo off @echo. setlocal enabledelayedexpansion if "%1" == "set" ( ...