dmesg命令来自英文词组“display message”的缩写,其功能是用于显示开机过程信息。Linux系统内核会将开机过程信息存储在环形缓冲区(ring buffer)中,随后再写入到/var/log/dmesg文件里,如果开机时来不及查看这些信息,则可以利用dmesg命令进行调取。

语法格式:dmesg [参数]

常用参数:

-c 清空环形缓冲区中的内容
-d 显示信息时间差
-D 禁止向终端输出信息
-E 启用向终端输出信息
-H 以更易读的格式输出信息
-k 显示内核信息
-l 设置输出级别
-L 显示彩色信息
-n 设置记录信息的层级
-r 显示原生消息缓冲区信息
-s 设置环形缓冲区的大小
-t 不显示消息时间戳
-T 显示易读的时间戳格式
-u 显示用户空间消息
-w 等待新消息
--help 显示帮助信息
--version 显示版本信息

参考示例

显示全部的系统开机过程信息:

[root@linuxcool ~]# dmesg

显示与指定硬盘设备相关的开机过程信息:

[root@linuxcool ~]# dmesg | grep sda
[    5.065202] sd 2:0:0:0: [sda] 41943040 512-byte logical blocks: (21.5 GB/20.0 GiB)
[    5.065253] sd 2:0:0:0: [sda] Write Protect is off
[    5.065255] sd 2:0:0:0: [sda] Mode Sense: 00 3a 00 00
[    5.065396] sd 2:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[    5.069757]  sda: sda1 sda2
[    5.083650] sd 2:0:0:0: [sda] Attached SCSI disk
[    8.379578] XFS (sda1): Mounting V5 Filesystem
[    9.009002] XFS (sda1): Ending clean mount

显示与内存相关的开机过程信息:

[root@linuxcool ~]# dmesg | grep memory 
[    0.000000] Base memory trampoline at [(____ptrval____)] 98000 size 24576
[    0.000000] Early memory node ranges
[    0.000000] PM: Registered nosave memory: [mem 0x00000000-0x00000fff]
[    0.000000] PM: Registered nosave memory: [mem 0x0009e000-0x0009efff]
[    0.000000] PM: Registered nosave memory: [mem 0x0009f000-0x0009ffff]
[    0.000000] PM: Registered nosave memory: [mem 0x000a0000-0x000dbfff]
[    0.000000] PM: Registered nosave memory: [mem 0x000dc000-0x000fffff]
[    0.000000] PM: Registered nosave memory: [mem 0x7fee0000-0x7fefefff]
[    0.000000] PM: Registered nosave memory: [mem 0x7feff000-0x7fefffff]
[    0.033593] Freeing SMP alternatives memory: 32K
[    1.716349] Freeing initrd memory: 26068K
[    1.893488] Non-volatile memory driver v1.3
[    2.374146] Freeing unused kernel memory: 2348K
[    2.382073] Freeing unused kernel memory: 2020K
[    2.382772] Freeing unused kernel memory: 280K
[    4.604351] [drm] Max dedicated hypervisor surface memory is 0 kiB
[    4.604352] [drm] Maximum display memory size is 262144 kiB
[    4.606362] [TTM] Zone  kernel: Available graphics memory: 1006652 kiB

清空环形缓冲区中的已有日志内容:

[root@linuxcool ~]# dmesg -c