Linux 内核日志——dmesg

时间:2023-03-08 22:06:14

有时Linux系统或者系统上运行的mysqld或者其它进程,会发生一些莫名其妙的问题,比如突然挂掉了,比如突然重启等等。在软件上找不到问题所在,此时我们应该怀疑硬件或者内核的问题,此时我们就可以使用 dmesg 来查看:

NAME
dmesg - print or control the kernel ring buffer SYNOPSIS
dmesg [-c] [-r] [-n level] [-s bufsize] DESCRIPTION
dmesg is used to examine or control the kernel ring buffer. The program helps users to print out their bootup messages. Instead of copying the messages by hand, the user need
only:
dmesg > boot.messages
and mail the boot.messages file to whoever can debug their problem. OPTIONS
-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 by default. (The default kernel
syslog buffer size was at first, since 1.3., since 2.1..) 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 prevents all messages,
except panic messages, from appearing on the console. All levels of messages are still written to /proc/kmsg,
so syslogd() 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. SEE ALSO
syslogd()

直接执行:dmesg 或者 dmesg > dmg.txt 就可以获得硬件信息和内核启动时的信息。