dmesg Linux故障工具:显示内核信息

发布时间: 更新时间: 总字数:360 阅读时间:1m 作者: IP上海 分享 网址

dmesg(display message)命令主要用来查看Linux内核信息(打印或控制内核环缓冲区),常用来排查系统故障,如硬件问题等

介绍

  • help
dmesg -h ...
$ 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 <file>           use the file instead of the kernel log buffer
 -f, --facility <list>       restrict output to defined facilities
 -H, --human                 human readable output
 -k, --kernel                display kernel messages
 -L, --color[=<when>]        colorize messages (auto, always or never)
                               colors are enabled by default
 -l, --level <list>          restrict output to defined levels
 -n, --console-level <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 <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 <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 version
...

常用命令

# 输入信息
dmesg

# 优化格式
dmesg -H

# 清除内核环形缓冲区
dmesg -c

# 显示时间
dmesg -e/-T

扩展

  • /dev/kmsg 有 dmesg 信息
  • 权限问题 sudo sysctl kernel.dmesg_restrict=0 或添加如下文件并重启
$ cat /etc/sysctl.d/10-local.conf
kernel.dmesg_restrict = 0
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数