Linux命令完全指南

Linux dmesg命令使用详解

dmesg命令被用于检查和控制内核的环形缓冲区,内核会将开机信息存储在ring buffer中。您若是开机时来不及查看信息,可利用dmesg来查看。开机信息保存在/var/log/dmesg文件里。

用法

1
2
3
4
5
6
dmesg [选项]
dmesg --clear
dmesg --read-clear [options]
dmesg --console-level level
dmesg --console-on
dmesg --console-off

选项

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
37
38
39
40
41
42
43
44
45
46
 -C, --clear                 清除内核环形缓冲区(ring butter)
-c, --read-clear 读取并清除所有消息
-D, --console-off 禁止向终端打印消息
-d, --show-delta 显示打印消息之间的时间差
-e, --reltime 以易读格式显示本地时间和时间差
-E, --console-on 启用向终端打印消息
-F, --file <文件> 用 文件 代替内核日志缓冲区
-f, --facility <列表> 将输出限制为定义的设施
-H, --human 易读格式输出
-k, --kernel 显示内核消息
-L, --color 显示彩色消息
-l, --level <列表> 限制输出级别
-n, --console-level <级别> 设置打印到终端的消息级别
-P, --nopager 不将输出通过管道传递给分页程序
-r, --raw 打印原生消息缓冲区
-S, --syslog 强制使用 syslog(2) 而非 /dev/kmsg
-s, --buffer-size <大小> 查询内核环形缓冲区所用的缓冲区大小
-T, --ctime 显示易读的时间戳(如果您使用了
SUSPEND/RESUME 则可能不准)
-t, --notime 不打印消息时间戳
-u, --userspace 显示用户空间消息
-w, --follow 等待新消息
-x, --decode 将设施和级别解码为可读的字符串

-h, --help 显示此帮助并退出
-V, --version 输出版本信息并退出

支持的日志设施:
kern - 内核消息
user - 随机的用户级消息
mail - 邮件系统
daemon - 系统守护进程
auth - 安全/认证消息
syslog - syslogd 内部生成的消息
lpr - 行打印机子系统
news - 网络新闻子系统

支持的日志级别(优先级):
emerg - 系统无法使用
alert - 操作必须立即执行
crit - 紧急条件
err - 错误条件
warn - 警告条件
notice - 正常但重要的条件
info - 信息
debug - 调试级别的消息

实例

1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# dmesg | head
Linux version 2.6.18-348.6.1.el5 ([email protected]) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)) #1 SMP Tue May 21 15:34:22 EDT 2013
BIOS-provided physical RAM map:
BIOS-e820: 0000000000010000 - 000000000009f400 (usable)
BIOS-e820: 000000000009f400 - 00000000000a0000 (reserved)
BIOS-e820: 00000000000f0000 - 0000000000100000 (reserved)
BIOS-e820: 0000000000100000 - 000000007f590000 (usable)
BIOS-e820: 000000007f590000 - 000000007f5e3000 (ACPI NVS)
BIOS-e820: 000000007f5e3000 - 000000007f5f0000 (ACPI data)
BIOS-e820: 000000007f5f0000 - 000000007f600000 (reserved)
BIOS-e820: 00000000e0000000 - 00000000e8000000 (reserved)

查看硬盘基础信息

1
2
3
4
5
6
7
8
dmesg | grep sda

[ 2.442555] sd 0:0:0:0: [sda] 488281250 512-byte logical blocks: (250 GB/232 GiB)
[ 2.442590] sd 0:0:0:0: [sda] Write Protect is off
[ 2.442592] sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
[ 2.442607] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 2.447533] sda: sda1
[ 2.448503] sd 0:0:0:0: [sda] Attached SCSI disk