Fork me on GitHub

Linux命令——dmesg

参考:Linux kernel buffer ring

Linux dmesg Command Tutorial for Beginners (5 Examples)

7 ‘dmesg’ Commands for Troubleshooting and Collecting Information of Linux Systems

前言

Linux启动是个复杂的流程,BIOS->MBR->boot loader。。。

boot loader阶段有Kernel以及initrd,Kernel通过initrd加载到bootable device的驱动后正式接管根目录文件系统,然后加载各种驱动,准备OS下程序运行环境等等。boot loader详细工作如下图。

Kernel做了这么多事情,有什么办法观察内核所作的工作吗?  dmesg可以。

使用

无参数

无参数使用dmesg时,会把内核buffer ring中的所有日志全部显示出来,直接看比较麻烦。我在自己的环境上测试,有1700多条日志

[root@localhost etc]# dmesg | wc -l
1725

通过日志等级缩小dmesg输出

这个是参考国外博客的,但是现在dmesg不允许这么用了

日志等级从低到高

info - 一些基本的信息说明

notice - 比 info 稍稍重要些

warn - 警示的信息,可能有问题,但是还不至于影响到某个 daemon 运行。基本上, info, notice, warn 这三个等级都是在通知一些基本信息,还不至于对系统运行造成影响

err - 一些重大的错误信息,例如配置档的某些配置值造成该服务服法启动, 通常通过 err 的错误告知

crit - 错误临界点

alert - 警告,问题很严重,必须立即采取行动

emerg - 系统已经几乎要死机的状态,大概只有硬件出问题,导致整个核心无法顺利运行,才会出现这样的情况

-c Clear the ring buffer contents after printing.

-r Print the raw message buffer, i.e., don’t strip the log level prefixes.

-s bufsize

Use a buffer of size bufsize to query the kernel ring buffer. This is 16392 by default. (The default kernel syslog buffer size was 4096 at first,
8192 since 1.3.54, 16384 since 2.1.113.) If you have set the kernel buffer to be larger than the default then this option can be used to view the
entire buffer.

-n level

Set the level at which logging of messages is done to the console. For example, -n 1 prevents all messages, except panic messages, from appearing on
the console. All levels of messages are still written to /proc/kmsg, so syslogd(8) can still be used to control exactly where kernel messages appear.
When the -n option is used, dmesg will not print or clear the kernel ring buffer.

When both options are used, only the last option on the command line will have an effect.

 

posted @ 2018-12-12 23:10  克拉默与矩阵  阅读(635)  评论(0编辑  收藏  举报