Linux常用命令-dmesg

命令

dmesg

描述

print or control the kernel ring buffer
查看系统内核日志

用法

1
dmesg [options]

选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Options:
-C 清除日志缓存
-c 读取并清除所有日志
-H 以可读形式显示
-k 显示内核日志
-L 显示颜色
-l 显示指定级别的日志,日志级别如下
-T 显示可读的时间戳,可能不准确
-t 不显示时间戳
-u 显示用户空间日志
-w 追加显示新日志
-x 显示详细的日志信息

日志级别
emerg - system is unusable
alert - action must be taken immediately
crit - critical conditions
err - error conditions
warn - warning conditions
notice - normal but significant condition
info - informational
debug - debug-level messages

注意

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$ dmesg -l err
[ 1.168998] sd 2:0:0:0: [sda] Assuming drive cache: write through
[ 2.701990] piix4_smbus 0000:00:07.3: SMBus Host Controller not enabled!

$ dmesg -x |head
kern :info : [ 0.000000] Initializing cgroup subsys cpuset
kern :info : [ 0.000000] Initializing cgroup subsys cpu
kern :info : [ 0.000000] Initializing cgroup subsys cpuacct
kern :notice: [ 0.000000] Linux version 3.10.0-1160.11.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Fri Dec 18 16:34:56 UTC 2020
kern :info : [ 0.000000] Command line: BOOT_IMAGE=/vmlinuz-3.10.0-1160.11.1.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap biosdevname=0 net.ifnames=0 rhgb quiet LANG=en_US.UTF-8
kern :info : [ 0.000000] Disabled fast string operations
...
# 过滤硬件信息
$ dmesg |grep sda
[ 1.168921] sd 2:0:0:0: [sda] 41943040 512-byte logical blocks: (21.4 GB/20.0 GiB)
[ 1.168945] sd 2:0:0:0: [sda] Write Protect is off
[ 1.168947] sd 2:0:0:0: [sda] Mode Sense: 61 00 00 00
[ 1.168996] sd 2:0:0:0: [sda] Cache data unavailable
[ 1.168998] sd 2:0:0:0: [sda] Assuming drive cache: write through
[ 1.169937] sda: sda1 sda2
[ 1.170157] sd 2:0:0:0: [sda] Attached SCSI disk
[ 2.845189] XFS (sda1): Mounting V5 Filesystem
[ 2.877457] XFS (sda1): Ending clean mount
$ dmesg |grep XFS
[ 1.510339] SGI XFS with ACLs, security attributes, no debug enabled
[ 1.513852] XFS (dm-0): Mounting V5 Filesystem
[ 1.523018] XFS (dm-0): Ending clean mount
[ 2.845189] XFS (sda1): Mounting V5 Filesystem
[ 2.877457] XFS (sda1): Ending clean mount
$ dmesg |grep Memory
[ 0.000000] Memory: 2004084k/2097152k available (7788k kernel code, 524k absent, 92544k reserved, 5954k data, 1984k init)
[ 0.117670] x86/mm: Memory block size: 128MB
$ dmesg |grep Network
[ 0.957434] e1000: Intel(R) PRO/1000 Network Driver - version 7.3.21-k8-NAPI
[ 1.346108] e1000 0000:02:00.0 eth0: Intel(R) PRO/1000 Network Connection
$ dmesg |grep cpu