dmesg 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

dmesg 命令安装:


-bash: dmesg: command not found

#Debian
apt-get install util-linux

#Ubuntu
apt-get install util-linux

#Arch Linux
pacman -S util-linux

#Kali Linux
apt-get install util-linux

#CentOS
yum install util-linux

#Fedora
dnf install util-linux

#Raspbian
apt-get install util-linux

#Docker
docker run cmd.cat/dmesg dmesg

dmesg 命令补充说明:


dmesg 命令的默认操作是从内核环缓冲区读取所有消息。内核环缓冲区是一种数据结构,它记录与内核操作相关的消息。 环形缓冲区是一种特殊类型的缓冲区,总是一个恒定的大小,在新消息进入时删除最旧的消息。

dmesg 命令语法:


dmesg [options]

dmesg 命令选项:


-c:显示信息后,清除ring buffer中的内容;
-s<缓冲区大小>:预设置为8196,刚好等于ring buffer的大小;
-n:设置记录信息的层级。
-C, --清楚 ring buffer.
-D, --console-off 禁用打印到控制台的消息。
-d, --show-delta 显示消息之间花费的时间戳和时间增量。 如果与--notime一起使用,则仅打印没有时间戳的时间增量。
-E, --console-on 启用打印消息到控制台。
-f, --facility list 将输出限制为已定义(逗号分隔)的设施列表。 对于所有支持的设施,请参阅--help输出。
-h, --help 打印帮助文本并退出。
-k, --kernel 打印内核消息。
-l, --level list 将输出限制为已定义(逗号分隔)的级别列表。 对于所有支持的级别,请参阅--help输出。
-n, --console-level level 设置将消息记录到控制台的级别。 级别是级别名称的级别编号或缩写。 
      例如,-n 1或-n警报可防止除紧急(恐慌)消息之外的所有消息出现在控制台上。 
      所有级别的消息仍然写入/ proc / kmsg,因此syslogd(8)仍可用于精确控制内核消息的显示位置。 
      使用-n选项时,dmesg不会打印或清除内核环缓冲区。 对于所有支持的级别,请参阅--help输出。
-r, --raw 打印原始消息缓冲区,即不剥离日志级别前缀。
-s, --buffer-size size 使用大小的缓冲区来查询内核环缓冲区。 默认情况下为16392。 如果已将内核缓冲区设置为大于默认值,则可以使用此选项查看整个缓冲区。
-T, --ctime 打印人类可读时间戳。 时间戳可能不准确; 在系统SUSPEND / RESUME之后,不会更新用于日志的时间源。
-t, --notime 不要打印内核的时间戳。
-u, --userspace 打印用户空间消息。
-V, --version 输出版本信息并退出。
-x, --decode 将设施和级别(优先级)编号解码为人类可读的前缀。

dmesg 命令实例


[root@TestMaster /var/log]
$ dmesg |head
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.10.0-957.10.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Mon Mar 18 15:06:45 UTC 2019
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.10.0-957.10.1.el7.x86_64 root=UUID=312381f6-4571-4cfa-b93b-7add4cbb8059 ro crashkernel=auto rhgb LANG=en_US.UTF-8 console=tty0 console=ttyS0,115200n8
[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[    0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000bffd9fff] usable

dmesg 仅显示与内存使用相关的内核消息:

[root@TestMaster /var/log]
$ dmesg | grep -i memory
[    0.000000] Base memory trampoline at [ffff8f9340099000] 99000 size 24576
[    0.000000] Reserving 161MB of memory at 688MB for crashkernel (System RAM: 8191MB)
[    0.000000] Early memory node ranges
[    0.000000] PM: Registered nosave memory: [mem 0x0009f000-0x0009ffff]
[    0.000000] PM: Registered nosave memory: [mem 0x000a0000-0x000effff]
[    0.000000] PM: Registered nosave memory: [mem 0x000f0000-0x000fffff]
[    0.000000] PM: Registered nosave memory: [mem 0xbffda000-0xbfffffff]
[    0.000000] PM: Registered nosave memory: [mem 0xc0000000-0xfeffbfff]
[    0.000000] PM: Registered nosave memory: [mem 0xfeffc000-0xfeffffff]
[    0.000000] PM: Registered nosave memory: [mem 0xff000000-0xfffbffff]
[    0.000000] PM: Registered nosave memory: [mem 0xfffc0000-0xffffffff]
[    0.000000] Memory: 4991300k/9437184k available (7668k kernel code, 1049120k absent, 400700k reserved, 6051k data, 1876k init)
[    0.000000] please try 'cgroup_disable=memory' option if you don't want memory cgroups
[    0.357447] Initializing cgroup subsys memory
[    1.004073] Freeing initrd memory: 18472k freed
[    1.128259] Non-volatile memory driver v1.3
[    1.130740] crash memory driver: version 1.1
[    1.243076] Freeing unused kernel memory: 1876k freed
[    1.248183] Freeing unused kernel memory: 512k freed
[    1.250888] Freeing unused kernel memory: 600k freed
[    1.700781] [TTM] Zone  kernel: Available graphics memory: 4004426 kiB
[    1.702519] [TTM] Zone   dma32: Available graphics memory: 2097152 kiB

dmesg 查看硬盘基础信息:

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

dmesg 彩色输出(在内核3.5.0及更高版本中可用):

$ dmesg -L


[    0.000000] MTRR variable ranges enabled:
[    0.000000]   0 base 0000C0000000 mask 3FFFC0000000 uncachable
[    0.000000]   1 disabled
[    0.000000]   2 disabled
[    0.000000]   3 disabled
[    0.000000]   4 disabled
[    0.000000]   5 disabled
[    0.000000]   6 disabled
[    0.000000]   7 disabled
[    0.000000] PAT configuration [0-7]: WB  WC  UC- UC  WB  WP  UC- UC  
[    0.000000] e820: last_pfn = 0xbffe0 max_arch_pfn = 0x400000000
[    0.000000] found SMP MP-table at [mem 0x000f0e80-0x000f0e8f] mapped at [ffffffffff200e80]
[    0.000000] Base memory trampoline at [ffff996b80099000] 99000 size 24576
[    0.000000] Using GB pages for direct mapping
[    0.000000] BRK [0x1d252000, 0x1d252fff] PGTABLE
[    0.000000] BRK [0x1d253000, 0x1d253fff] PGTABLE
[    0.000000] BRK [0x1d254000, 0x1d254fff] PGTABLE
[    0.000000] BRK [0x1d255000, 0x1d255fff] PGTABLE
[    0.000000] RAMDISK: [mem 0x35cde000-0x36e66fff]
[    0.000000] Early table checksum verification disabled
[    0.000000] ACPI: RSDP 00000000000f0c20 00014 (v00 BOCHS )
[    0.000000] ACPI: RSDT 00000000bffe1c3f 00034 (v01 BOCHS  BXPCRSDT 00000001 BXPC 00000001)
[    0.000000] ACPI: FACP 00000000bffe0b52 00074 (v01 BOCHS  BXPCFACP 00000001 BXPC 00000001)
[    0.000000] ACPI: DSDT 00000000bffe0040 00B12 (v01 BOCHS  BXPCDSDT 00000001 BXPC 00000001)
[    0.000000] ACPI: FACS 00000000bffe0000 00040
[    0.000000] ACPI: SSDT 00000000bffe0bc6 00EA1 (v01 BOCHS  BXPCSSDT 00000001 BXPC 00000001)
[    0.000000] ACPI: APIC 00000000bffe1a67 000B0 (v01 BOCHS  BXPCAPIC 00000001 BXPC 00000001)
[    0.000000] ACPI: SRAT 00000000bffe1b17 00128 (v01 BOCHS  BXPCSRAT 00000001 BXPC 00000001)

....

[    2.024077] virtio-pci 0000:00:03.0: irq 30 for MSI/MSI-X
[    2.024099] virtio-pci 0000:00:03.0: irq 31 for MSI/MSI-X
[    2.024110] [TTM] Zone  kernel: Available graphics memory: 8132896 kiB
[    2.024120] virtio-pci 0000:00:03.0: irq 32 for MSI/MSI-X
[    2.024208] virtio-pci 0000:00:03.0: irq 33 for MSI/MSI-X
[    2.024230] virtio-pci 0000:00:03.0: irq 34 for MSI/MSI-X
[    2.024350] virtio_blk virtio2: [vda] 83886080 512-byte logical blocks (42.9 GB/40.0 GiB)
[    2.029596] [TTM] Zone   dma32: Available graphics memory: 2097152 kiB
[    2.029596] [TTM] Initializing pool allocator
[    2.029607] [TTM] Initializing DMA pool allocator
[    2.029788]  vda: vda1
[    2.030003] virtio-pci 0000:00:04.0: irq 35 for MSI/MSI-X
[    2.030009] [drm] fb mappable at 0xFC000000
[    2.030010] [drm] vram aper at 0xFC000000
[    2.030010] [drm] size 33554432
[    2.030011] [drm] fb depth is 24
[    2.030011] [drm]    pitch is 3072
[    2.030024] virtio-pci 0000:00:04.0: irq 36 for MSI/MSI-X
[    2.030250] virtio-pci 0000:00:06.0: irq 37 for MSI/MSI-X
[    2.030271] virtio-pci 0000:00:06.0: irq 38 for MSI/MSI-X
[    2.031266] virtio_blk virtio3: [vdb] 4294967296 512-byte logical blocks (2.19 TB/2.00 TiB)
[    2.031837]  vdb: vdb1
[    2.070231] fbcon: cirrusdrmfb (fb0) is primary device
[    2.087960] Console: switching to colour frame buffer device 128x48
[    2.091777] cirrus 0000:00:02.0: fb0: cirrusdrmfb frame buffer device
[    2.095490] [drm] Initialized cirrus 1.0.0 20110418 for 0000:00:02.0 on minor 0
[    2.159992] tsc: Refined TSC clocksource calibration: 2499.914 MHz
[    2.242000] EXT4-fs (vda1): mounted filesystem with ordered data mode. Opts: (null)
[    2.494407] systemd-journald[129]: Received SIGTERM from PID 1 (systemd).
[    2.786219] SELinux:  Disabled at runtime.
[    2.787371] SELinux:  Unregistering netfilter hooks
[    2.831960] type=1404 audit(1558533564.974:2): selinux=0 auid=4294967295 ses=4294967295
[    2.841118] systemd[1]: RTC configured in localtime, applying delta of 480 minutes to system time.
[    2.883609] ip_tables: (C) 2000-2006 Netfilter Core Team
[    2.885177] systemd[1]: Inserted module 'ip_tables'
[    3.208658] EXT4-fs (vda1): re-mounted. Opts: (null)
[    3.277568] systemd-journald[1718]: Received request to flush runtime journal from PID 1
[    3.918400] input: PC Speaker as /devices/platform/pcspkr/input/input5
[    3.921555] piix4_smbus 0000:00:01.3: SMBus Host Controller at 0x700, revision 0
[    4.001147] cryptd: max_cpu_qlen set to 1000
[    4.019704] AVX2 version of gcm_enc/dec engaged.
[    4.022049] AES CTR mode by8 optimization enabled
[    4.042413] alg: No test for __gcm-aes-aesni (__driver-gcm-aes-aesni)
[    4.044981] alg: No test for __generic-gcm-aes-aesni (__driver-generic-gcm-aes-aesni)
[    4.144075] SGI XFS with ACLs, security attributes, no debug enabled
[    4.168642] XFS (vdb1): Mounting V5 Filesystem
[    4.207767] ppdev: user-space parallel port driver
[    4.234868] XFS (vdb1): Ending clean mount
[    4.303555] type=1305 audit(1558504766.445:3): audit_pid=3266 old=0 auid=4294967295 ses=4294967295 res=1
[   12.348860] random: crng init done
[1116479.439167] monitor[32767]: segfault at c0 ip 00007f617ab274ad sp 00007f61777834a0 error 4 in libc-2.17.so[7f617aadf000+1c2000]
[4336988.248895] TCP: request_sock_TCP: Possible SYN flooding on port 80. Sending cookies.  Check SNMP counters.
[31484989.116858] AliSecGuard: loading out-of-tree module taints kernel.
[31484989.117708] AliSecGuard: module verification failed: signature and/or required key missing - tainting kernel

dmesg 命令扩展阅读:




dmesg 命令评论

共收录到 500Linux 命令