dmesg命令对于设备故障的诊断是非常重要的。在dmesg命令的帮助下进行硬件的连接或断开连接操作时,我们可以看到硬件的检测或者断开连接的信息。dmesg命令在多数基于Linux和Unix的操作系统中都可以使用。
 
ASP站长网下面我们展示一些最负盛名的dmesg命令工具以及其实际使用举例。
 
dmesg命令的使用语法如下。
 
# dmesg [options...]
 
1. 列出加载到内核中的所有驱动
 
我们可以使用如‘more’。 ‘tail’, ‘less ’或者‘grep’文字处理工具来处理‘dmesg’命令的输出。由于dmesg日志的输出不适合在一页中完全显示,因此我们使用管道(pipe)将其输出送到more或者less命令单页显示。
 
linuxidc@linuxidc:~/linuxidc.com$ dmesg | more
[    0.000000] Linux version 4.18.0-17-generic (buildd@lgw01-amd64-021) (gcc ver
sion 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #18~18.04.1-Ubuntu SMP Fri Mar 15 15:27:12
UTC 2019 (Ubuntu 4.18.0-17.18~18.04.1-generic 4.18.20)
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.18.0-17-generic root=UUI
D=21f64724-a9be-43a7-8e83-2e7ffd1ba2a3 ro quiet splash
[    0.000000] KERNEL supported cpus:
[    0.000000]  Intel GenuineIntel
[    0.000000]  AMD AuthenticAMD
[    0.000000]  Centaur CentaurHauls
[    0.000000] Disabled fast string operations
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point regi
sters'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes,
using 'standard' format.
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009e7ff] usable
[    0.000000] BIOS-e820: [mem 0x000000000009e800-0x000000000009ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000000dc000-0x00000000000fffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000bfecffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000bfed0000-0x00000000bfefefff] ACPI data
--更多--
 
Linux dmesg命令使用示例
 
linuxidc@linuxidc:~/linuxidc.com$ dmesg | less
 
Linux dmesg命令使用示例
 
2. 列出所有被检测到的硬件
 
要显示所有被内核检测到的硬盘设备,你可以使用‘grep’命令搜索‘sda’关键词,如下:
 
linuxidc@linuxidc:~/linuxidc.com$ dmesg | grep sda
[    3.323824] sd 26:0:0:0: [sda] 125829120 512-byte logical blocks: (64.4 GB/60.0 GiB)
[    3.323848] sd 26:0:0:0: [sda] Write Protect is off
[    3.323850] sd 26:0:0:0: [sda] Mode Sense: 61 00 00 00
[    3.323886] sd 26:0:0:0: [sda] Cache data unavailable
[    3.323887] sd 26:0:0:0: [sda] Assuming drive cache: write through
[    3.325104]  sda: sda1
[    3.325583] sd 26:0:0:0: [sda] Attached SCSI disk
[    3.690525] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
[    4.265965] EXT4-fs (sda1): re-mounted. Opts: errors=remount-ro
 
Linux dmesg命令使用示例
 
注解 ‘sda’表示第一块 SATA硬盘,‘sdb’表示第二块SATA硬盘。若想查看IDE硬盘搜索‘hda’或‘hdb’关键词。
 
3. 只输出dmesg命令的前20行日志
 
在‘dmesg’命令后跟随‘head’命令来显示开始几行,‘dmesg | head -20′命令将显示开始的前20行。
 
[    0.000000]  AMD AuthenticAMD
[    0.000000]  Centaur CentaurHauls
[    0.000000] Disabled fast string operations
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset[2]:  576, xstate_sizes[2]:  256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009e7ff] usable
[    0.000000] BIOS-e820: [mem 0x000000000009e800-0x000000000009ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000000dc000-0x00000000000fffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000bfecffff] usable
[    0.000000] BIOS-e820: [mem 0x00000000bfed0000-0x00000000bfefefff] ACPI data
[    0.000000] BIOS-e820: [mem 0x00000000bfeff000-0x00000000bfefffff] ACPI NVS
[    0.000000] BIOS-e820: [mem 0x00000000bff00000-0x00000000bfffffff] usable
 
Linux dmesg命令使用示例
 
4. 只输出dmesg命令最后20行日志
 
在‘dmesg’命令后跟随‘tail’命令(‘ dmesg | tail -20’)来输出‘dmesg’命令的最后20行日志,当你插入可移动设备时它是非常有用的。
 
linuxidc@linuxidc:~/linuxidc.com$ dmesg | tail -20
[  12.162939] RAPL PMU: hw unit of domain dram 2^-0 Joules
[  12.162939] RAPL PMU: hw unit of domain pp1-gpu 2^-0 Joules
[  12.162940] RAPL PMU: hw unit of domain psys 2^-0 Joules
[  12.429921] cryptd: max_cpu_qlen set to 1000
[  12.536473] AVX2 version of gcm_enc/dec engaged.
[  12.536474] AES CTR mode by8 optimization enabled
[  12.732314] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[  12.732315] Bluetooth: BNEP filters: protocol multicast
[  12.732319] Bluetooth: BNEP socket layer initialized
[  20.858894] [drm:vmw_stdu_crtc_page_flip [vmwgfx]] *ERROR* Page flip error -16.
[  114.030097] sched: RT throttling activated
[  114.092905] Bluetooth: RFCOMM TTY layer initialized
[  114.092909] Bluetooth: RFCOMM socket layer initialized
[  114.092912] Bluetooth: RFCOMM ver 1.11
[  115.876999] rfkill: input handler disabled
[  117.336287] show_signal_msg: 28 callbacks suppressed
[  117.336290] vmtoolsd[2585]: segfault at 1710 ip 0000000000001710 sp 00007ffc7af6abe8 error 14 in vmtoolsd[5631cce9d000+ac000]
[  117.336294] Code: Bad RIP value.
[  121.476306] ISO 9660 Extensions: Microsoft Joliet Level 3
[  121.487278] ISO 9660 Extensions: RRIP_1991A

dawei

【声明】:九江站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。