赞
踩
dmesg’命令设备故障的诊断是非常重要的。在‘dmesg’命令的帮助下进行硬件的连接或断开连接操作时,我们可以看到硬件的检测或者断开连接的信息。‘dmesg’命令在多数基于Linux和Unix的操作系统中都可以使用。
我们可以使用如‘more’。 ‘tail’, ‘less ’或者‘grep’文字处理工具来处理‘dmesg’命令的输出。由于dmesg日志的输出不适合在一页中完全显示,因此我们使用管道(pipe)将其输出送到more或者less命令单页显示。
[root@hanyw-Bash-Python ten-command-performance]# dmesg | more [ 0.000000] Linux version 5.14.0-402.el9.x86_64 (mockbuild@x86-05.stream.rdu2.redhat.com) (gcc (GCC) 11.4.1 2023060 5 (Red Hat 11.4.1-2), GNU ld version 2.35.2-42.el9) #1 SMP PREEMPT_DYNAMIC Thu Dec 21 19:46:35 UTC 2023 [ 0.000000] The list of certified hardware and cloud instances for Red Hat Enterprise Linux 9 can be viewed at the Red Hat Ecosystem Catalog, https://catalog.redhat.com. [ 0.000000] Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64 root=/dev/mapper/cs-root ro rd.lvm. lv=cs/root [ 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 'compacted' format. [ 0.000000] signal: max sigframe size: 1776 [ 0.000000] BIOS-provided physical RAM map: [ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ebff] usable [ 0.000000] BIOS-e820: [mem 0x000000000009ec00-0x000000000009ffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000000dc000-0x00000000000fffff] reserved [ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000007fedffff] usable [ 0.000000] BIOS-e820: [mem 0x000000007fee0000-0x000000007fefefff] ACPI data [ 0.000000] BIOS-e820: [mem 0x000000007feff000-0x000000007fefffff] ACPI NVS [ 0.000000] BIOS-e820: [mem 0x000000007ff00000-0x000000007fffffff] usable [ 0.000000] BIOS-e820: [mem 0x00000000f0000000-0x00000000f7ffffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000fec00000-0x00000000fec0ffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000fee00000-0x00000000fee00fff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000fffe0000-0x00000000ffffffff] reserved [ 0.000000] NX (Execute Disable) protection: active [ 0.000000] SMBIOS 2.7 present. [ 0.000000] DMI: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020 [ 0.000000] vmware: hypercall mode: 0x02 [ 0.000000] Hypervisor detected: VMware [ 0.000000] vmware: TSC freq read from hypervisor : 3600.000 MHz [ 0.000000] vmware: Host bus clock speed read from hypervisor : 66000000 Hz --更多--
如下的指令也是类似的区别。
dmesg | less
输出如下。
[root@hanyw-Bash-Python ten-command-performance]# dmesg | less [ 0.000000] Linux version 5.14.0-402.el9.x86_64 (mockbuild@x86-05.stream.rdu2.redhat.com) (gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2), GNU ld version 2.35.2-42.el9) #1 SMP PREEMPT_DYNAMIC Thu Dec 21 19:46:35 UTC 2023 [ 0.000000] The list of certified hardware and cloud instances for Red Hat Enterprise Linux 9 can be viewed at the Red Hat Ecosystem Catalog, https://catalog.redhat.com. [ 0.000000] Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64 root=/dev/mapper/cs-root ro rd.lvm.lv=cs/root [ 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 'compacted' format. [ 0.000000] signal: max sigframe size: 1776 [ 0.000000] BIOS-provided physical RAM map: [ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ebff] usable [ 0.000000] BIOS-e820: [mem 0x000000000009ec00-0x000000000009ffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000000dc000-0x00000000000fffff] reserved [ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000007fedffff] usable [ 0.000000] BIOS-e820: [mem 0x000000007fee0000-0x000000007fefefff] ACPI data [ 0.000000] BIOS-e820: [mem 0x000000007feff000-0x000000007fefffff] ACPI NVS [ 0.000000] BIOS-e820: [mem 0x000000007ff00000-0x000000007fffffff] usable [ 0.000000] BIOS-e820: [mem 0x00000000f0000000-0x00000000f7ffffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000fec00000-0x00000000fec0ffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000fee00000-0x00000000fee00fff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000fffe0000-0x00000000ffffffff] reserved [ 0.000000] NX (Execute Disable) protection: active [ 0.000000] SMBIOS 2.7 present. [ 0.000000] DMI: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020 [ 0.000000] vmware: hypercall mode: 0x02 [ 0.000000] Hypervisor detected: VMware [ 0.000000] vmware: TSC freq read from hypervisor : 3600.000 MHz [ 0.000000] vmware: Host bus clock speed read from hypervisor : 66000000 Hz [ 0.000000] vmware: using clock offset of 26849061647 ns [ 0.000020] tsc: Detected 3600.000 MHz processor [ 0.001616] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved [ 0.001619] e820: remove [mem 0x000a0000-0x000fffff] usable [ 0.001623] last_pfn = 0x80000 max_arch_pfn = 0x400000000 [ 0.001642] total RAM covered: 3072M [ 0.001885] Found optimal setting for mtrr clean up [ 0.001886] gran_size: 64K chunk_size: 64K num_reg: 2 lose cover RAM: 0G [ 0.001889] MTRR map: 6 entries (5 fixed + 1 variable; max 21), built from 8 variable MTRRs [ 0.001890] x86/PAT: Configuration [0-7]: WB WC UC- UC WB WP UC- WT [ 0.009247] found SMP MP-table at [mem 0x000f6a70-0x000f6a7f] :
要显示所有被内核检测到的硬盘设备,你可以使用‘grep’命令搜索‘sda’关键词,如下
[root@hanyw-Bash-Python ten-command-performance]# dmesg |grep sd[a-z]
[ 0.000000] Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64 root=/dev/mapper/cs-root ro rd.lvm.lv=cs/root
[ 0.150022] Kernel command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64 root=/dev/mapper/cs-root ro rd.lvm.lv=cs/root
[ 0.150061] Unknown kernel command line parameters "BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64", will be passed to user space.
[ 3.366214] BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64
[ 5.559567] sd 2:0:0:0: [sda] 251658240 512-byte logical blocks: (129 GB/120 GiB)
[ 5.559645] sd 2:0:0:0: [sda] Write Protect is off
[ 5.559647] sd 2:0:0:0: [sda] Mode Sense: 61 00 00 00
[ 5.559754] sd 2:0:0:0: [sda] Cache data unavailable
[ 5.559755] sd 2:0:0:0: [sda] Assuming drive cache: write through
[ 5.569553] sda: sda1 sda2
[ 5.569701] sd 2:0:0:0: [sda] Attached SCSI disk
[ 25.628710] XFS (sda1): Mounting V5 Filesystem 33b3fa8b-f02c-409d-afc0-cccd91030610
[ 31.721751] XFS (sda1): Ending clean mount
__ 注解 sda 表示第一块 SATA硬盘,sdb表示第二块SATA硬盘。若想查看IDE硬盘搜索hda或hdb关键词。__
在‘dmesg’命令后跟随‘head’命令来显示开始几行,‘dmesg | head -30′命令将显示开始的前20行
[root@hanyw-Bash-Python ~]# dmesg | head -30 [ 0.000000] Linux version 5.14.0-402.el9.x86_64 (mockbuild@x86-05.stream.rdu2.redhat.com) (gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2), GNU ld version 2.35.2-42.el9) #1 SMP PREEMPT_DYNAMIC Thu Dec 21 19:46:35 UTC 2023 [ 0.000000] The list of certified hardware and cloud instances for Red Hat Enterprise Linux 9 can be viewed at the Red Hat Ecosystem Catalog, https://catalog.redhat.com. [ 0.000000] Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64 root=/dev/mapper/cs-root ro rd.lvm.lv=cs/root [ 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 'compacted' format. [ 0.000000] signal: max sigframe size: 1776 [ 0.000000] BIOS-provided physical RAM map: [ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009ebff] usable [ 0.000000] BIOS-e820: [mem 0x000000000009ec00-0x000000000009ffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000000dc000-0x00000000000fffff] reserved [ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000007fedffff] usable [ 0.000000] BIOS-e820: [mem 0x000000007fee0000-0x000000007fefefff] ACPI data [ 0.000000] BIOS-e820: [mem 0x000000007feff000-0x000000007fefffff] ACPI NVS [ 0.000000] BIOS-e820: [mem 0x000000007ff00000-0x000000007fffffff] usable [ 0.000000] BIOS-e820: [mem 0x00000000f0000000-0x00000000f7ffffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000fec00000-0x00000000fec0ffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000fee00000-0x00000000fee00fff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000fffe0000-0x00000000ffffffff] reserved [ 0.000000] NX (Execute Disable) protection: active [ 0.000000] SMBIOS 2.7 present. [ 0.000000] DMI: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020 [ 0.000000] vmware: hypercall mode: 0x02 [ 0.000000] Hypervisor detected: VMware [ 0.000000] vmware: TSC freq read from hypervisor : 3600.000 MHz [ 0.000000] vmware: Host bus clock speed read from hypervisor : 66000000 Hz [ 0.000000] vmware: using clock offset of 26849061647 ns
在‘dmesg’命令后跟随‘tail’命令(‘ dmesg | tail -fn20’)来输出‘dmesg’命令的最后20行日志,当你插入可移动设备时它是非常有用的。
[root@hanyw-Bash-Python ~]# dmesg | tail -fn 20 [ 25.739895] vmwgfx 0000:00:0f.0: [drm] DMA map mode: Caching DMA mappings. [ 25.740440] vmwgfx 0000:00:0f.0: [drm] Legacy memory limits: VRAM = 4096 kB, FIFO = 256 kB, surface = 0 kB [ 25.740442] vmwgfx 0000:00:0f.0: [drm] MOB limits: max mob size = 262144 kB, max mob pages = 196608 [ 25.740444] vmwgfx 0000:00:0f.0: [drm] Max GMR ids is 64 [ 25.740445] vmwgfx 0000:00:0f.0: [drm] Max number of GMR pages is 65536 [ 25.740446] vmwgfx 0000:00:0f.0: [drm] Maximum display memory size is 262144 kiB [ 25.766524] vmwgfx 0000:00:0f.0: [drm] Screen Target display unit initialized [ 25.770299] vmwgfx 0000:00:0f.0: [drm] Fifo max 0x00040000 min 0x00001000 cap 0x0000077f [ 25.770815] vmwgfx 0000:00:0f.0: [drm] Using command buffers with DMA pool. [ 25.770821] vmwgfx 0000:00:0f.0: [drm] Available shader model: Legacy. [ 25.845914] [drm] Initialized vmwgfx 2.20.0 20211206 for 0000:00:0f.0 on minor 0 [ 25.852749] fbcon: vmwgfxdrmfb (fb0) is primary device [ 25.853553] Console: switching to colour frame buffer device 160x50 [ 25.856173] vmwgfx 0000:00:0f.0: [drm] fb0: vmwgfxdrmfb frame buffer device [ 31.721751] XFS (sda1): Ending clean mount [ 36.632583] NET: Registered PF_VSOCK protocol family [ 47.484728] Warning: Unmaintained driver is detected: ip_set [ 47.484730] Warning: Deprecated Driver is detected: ip_set will not be maintained in a future major release and may be disabled [ 47.694148] vmxnet3 0000:03:00.0 ens160: intr type 3, mode 0, 2 vectors allocated [ 47.694537] vmxnet3 0000:03:00.0 ens160: NIC Link is Up 10000 Mbps
由于‘dmesg’命令的输出实在太长了,在其中搜索某个特定的字符串是非常困难的。因此,有必要过滤出一些包含‘usb’ ‘dma’ ‘tty’ ‘memory’等字符串的日志行。grep 命令 的‘-i’选项表示忽略大小写
[root@hanyw-Bash-Python ~]# dmesg | grep -i memory [ 0.009403] ACPI: Reserving FACP table memory at [mem 0x7fefee73-0x7fefef66] [ 0.009404] ACPI: Reserving DSDT table memory at [mem 0x7feead55-0x7fefee72] [ 0.009405] ACPI: Reserving FACS table memory at [mem 0x7fefffc0-0x7fefffff] [ 0.009405] ACPI: Reserving FACS table memory at [mem 0x7fefffc0-0x7fefffff] [ 0.009406] ACPI: Reserving BOOT table memory at [mem 0x7feead2d-0x7feead54] [ 0.009406] ACPI: Reserving APIC table memory at [mem 0x7feea5eb-0x7feead2c] [ 0.009407] ACPI: Reserving MCFG table memory at [mem 0x7feea5af-0x7feea5ea] [ 0.009407] ACPI: Reserving SRAT table memory at [mem 0x7fee9757-0x7fee9ffe] [ 0.009408] ACPI: Reserving HPET table memory at [mem 0x7fee971f-0x7fee9756] [ 0.009408] ACPI: Reserving WAET table memory at [mem 0x7fee96f7-0x7fee971e] [ 0.009720] Early memory node ranges [ 0.026936] PM: hibernation: Registered nosave memory: [mem 0x00000000-0x00000fff] [ 0.026938] PM: hibernation: Registered nosave memory: [mem 0x0009e000-0x0009efff] [ 0.026938] PM: hibernation: Registered nosave memory: [mem 0x0009f000-0x0009ffff] [ 0.026939] PM: hibernation: Registered nosave memory: [mem 0x000a0000-0x000dbfff] [ 0.026939] PM: hibernation: Registered nosave memory: [mem 0x000dc000-0x000fffff] [ 0.026940] PM: hibernation: Registered nosave memory: [mem 0x7fee0000-0x7fefefff] [ 0.026941] PM: hibernation: Registered nosave memory: [mem 0x7feff000-0x7fefffff] [ 0.175052] Memory: 260860K/2096628K available (16384K kernel code, 5616K rwdata, 11640K rodata, 3872K init, 6008K bss, 156564K reserved, 0K cma-reserved) [ 0.697805] x86/mm: Memory block size: 128MB [ 1.961405] Non-volatile memory driver v1.3 [ 2.915414] Freeing initrd memory: 35840K [ 3.269535] Freeing unused decrypted memory: 2028K [ 3.270606] Freeing unused kernel image (initmem) memory: 3872K [ 3.273128] Freeing unused kernel image (rodata/data gap) memory: 648K [ 25.740440] vmwgfx 0000:00:0f.0: [drm] Legacy memory limits: VRAM = 4096 kB, FIFO = 256 kB, surface = 0 kB [ 25.740446] vmwgfx 0000:00:0f.0: [drm] Maximum display memory size is 262144 kiB
使用dmesg -T可以显示对应事件的时间戳。
使用dmesg -H指令,人性化显示信息,如下图所示。
服务器在初始化启动和启动后运行的一段时间内,如果有对应的报错,会将报错信息进行收集,然后通过dmesg指令可以查看,如下。
[root@hanyw-Bash-Python ~]# dmesg -T |grep -i 'error\|fail\|warn' [一 1月 29 16:25:04 2024] pci 0000:00:15.3: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:15.4: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:15.5: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:15.6: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:15.7: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:16.3: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:16.4: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:16.5: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:16.6: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:16.7: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:17.3: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:17.4: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:17.5: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:17.6: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:17.7: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.2: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.3: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.4: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.5: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.6: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.7: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.7: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.6: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.5: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.4: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.3: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:18.2: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:17.7: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:17.6: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:17.5: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:17.4: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:17.3: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:16.7: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:16.6: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:16.5: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:16.4: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:16.3: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:15.7: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:15.6: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:15.5: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:15.4: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:04 2024] pci 0000:00:15.3: BAR 13: failed to assign [io size 0x1000] [一 1月 29 16:25:08 2024] Warning: Unmaintained driver is detected: mptbase [一 1月 29 16:25:08 2024] Warning: Unmaintained driver is detected: mptscsih [一 1月 29 16:25:08 2024] Warning: Unmaintained driver is detected: mptspi [一 1月 29 16:25:50 2024] Warning: Unmaintained driver is detected: ip_set [一 1月 29 16:25:50 2024] Warning: Deprecated Driver is detected: ip_set will not be maintained in a future major release and may be disabled
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。