您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關Linux中怎么使用dmesg命令處理故障和收集系統信息,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
1. 列出加載到內核中的所有驅動
我們可以使用如‘more’。 ‘tail’, ‘less ’或者‘grep’文字處理工具來處理‘dmesg’命令的輸出。由于dmesg日志的輸出不適合在一頁中完全顯示,因此我們使用管道(pipe)將其輸出送到more或者less命令單頁顯示。
[root@tecmint.com ~]# dmesg | more[root@tecmint.com ~]# dmesg | less
[ 0.000000] Initializing cgroup subsys cpuset[ 0.000000] Initializing cgroup subsys cpu[ 0.000000] Initializing cgroup subsys cpuacct[ 0.000000] Linux version 3.11.0-13-generic (buildd@aatxe) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8) ) #20-Ubuntu SMP Wed Oct 23 17:26:33 UTC 2013 (Ubuntu 3.11.0-13.20-generic 3.11.6)[ 0.000000] KERNEL supported cpus:[ 0.000000] Intel GenuineIntel[ 0.000000] AMD AuthenticAMD[ 0.000000] NSC Geode by NSC[ 0.000000] Cyrix CyrixInstead[ 0.000000] Centaur CentaurHauls[ 0.000000] Transmeta GenuineTMx86[ 0.000000] Transmeta TransmetaCPU[ 0.000000] UMC UMC UMC UMC[ 0.000000] e820: BIOS-provided physical RAM map:[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000007dc08bff] usable[ 0.000000] BIOS-e820: [mem 0x000000007dc08c00-0x000000007dc5cbff] ACPI NVS[ 0.000000] BIOS-e820: [mem 0x000000007dc5cc00-0x000000007dc5ebff] ACPI data[ 0.000000] BIOS-e820: [mem 0x000000007dc5ec00-0x000000007fffffff] reserved[ 0.000000] BIOS-e820: [mem 0x00000000e0000000-0x00000000efffffff] reserved[ 0.000000] BIOS-e820: [mem 0x00000000fec00000-0x00000000fed003ff] reserved[ 0.000000] BIOS-e820: [mem 0x00000000fed20000-0x00000000fed9ffff] reserved[ 0.000000] BIOS-e820: [mem 0x00000000fee00000-0x00000000feefffff] reserved[ 0.000000] BIOS-e820: [mem 0x00000000ffb00000-0x00000000ffffffff] reserved[ 0.000000] NX (Execute Disable) protection: active.....
要顯示所有被內核檢測到的硬盤設備,你可以使用‘grep’命令搜索‘sda’關鍵詞,如下:
[root@tecmint.com ~]# dmesg | grep sda [ 1.280971] sd 2:0:0:0: [sda] 488281250 512-byte logical blocks: (250 GB/232 GiB)[ 1.281014] sd 2:0:0:0: [sda] Write Protect is off[ 1.281016] sd 2:0:0:0: [sda] Mode Sense: 00 3a 00 00[ 1.281039] sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA[ 1.359585] sda: sda1 sda2 < sda5 sda6 sda7 sda8 >[ 1.360052] sd 2:0:0:0: [sda] Attached SCSI disk[ 2.347887] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)[ 22.928440] Adding 3905532k swap on /dev/sda6. Priority:-1 extents:1 across:3905532k FS[ 23.950543] EXT4-fs (sda1): re-mounted. Opts: errors=remount-ro[ 24.134016] EXT4-fs (sda5): mounted filesystem with ordered data mode. Opts: (null)[ 24.330762] EXT4-fs (sda7): mounted filesystem with ordered data mode. Opts: (null)[ 24.561015] EXT4-fs (sda8): mounted filesystem with ordered data mode. Opts: (null)
注解 ‘sda’表示***塊 SATA硬盤,‘sdb’表示第二塊SATA硬盤。若想查看IDE硬盤搜索‘hda’或‘hdb’關鍵詞。
在‘dmesg’命令后跟隨‘head’命令來顯示開始幾行,‘dmesg | head -20′命令將顯示開始的前20行。
[root@tecmint.com ~]# dmesg | head -20 [ 0.000000] Initializing cgroup subsys cpuset[ 0.000000] Initializing cgroup subsys cpu[ 0.000000] Initializing cgroup subsys cpuacct[ 0.000000] Linux version 3.11.0-13-generic (buildd@aatxe) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8) ) #20-Ubuntu SMP Wed Oct 23 17:26:33 UTC 2013 (Ubuntu 3.11.0-13.20-generic 3.11.6)[ 0.000000] KERNEL supported cpus:[ 0.000000] Intel GenuineIntel[ 0.000000] AMD AuthenticAMD[ 0.000000] NSC Geode by NSC[ 0.000000] Cyrix CyrixInstead[ 0.000000] Centaur CentaurHauls[ 0.000000] Transmeta GenuineTMx86[ 0.000000] Transmeta TransmetaCPU[ 0.000000] UMC UMC UMC UMC[ 0.000000] e820: BIOS-provided physical RAM map:[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000007dc08bff] usable[ 0.000000] BIOS-e820: [mem 0x000000007dc08c00-0x000000007dc5cbff] ACPI NVS[ 0.000000] BIOS-e820: [mem 0x000000007dc5cc00-0x000000007dc5ebff] ACPI data[ 0.000000] BIOS-e820: [mem 0x000000007dc5ec00-0x000000007fffffff] reserved
在‘dmesg’命令后跟隨‘tail’命令(‘ dmesg | tail -20’)來輸出‘dmesg’命令的***20行日志,當你插入可移動設備時它是非常有用的。
[root@tecmint.com ~]# dmesg | tail -20 parport0: PC-style at 0x378, irq 7 [PCSPP,TRISTATE]ppdev: user-space parallel port driverEXT4-fs (sda1): mounted filesystem with ordered data modeAdding 2097144k swap on /dev/sda2. Priority:-1 extents:1 across:2097144kreadahead-disable-service: delaying service auditdip_tables: (C) 2000-2006 Netfilter Core Teamnf_conntrack version 0.5.0 (16384 buckets, 65536 max)NET: Registered protocol family 10lo: Disabled Privacy Extensionse1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: NoneSlow work thread pool: Starting upSlow work thread pool: ReadyFS-Cache: LoadedCacheFiles: LoadedCacheFiles: Security denies permission to nominate security context: error -95eth0: no IPv6 routers presenttype=1305 audit(1398268784.593:18630): audit_enabled=0 old=1 auid=4294967295 ses=4294967295 res=1readahead-collector: starting delayed service auditdreadahead-collector: sortingreadahead-collector: finished
由于‘dmesg’命令的輸出實在太長了,在其中搜索某個特定的字符串是非常困難的。因此,有必要過濾出一些包含‘usb’ ‘dma’ ‘tty’ ‘memory’等字符串的日志行。grep 命令 的‘-i’選項表示忽略大小寫。
[root@tecmint.com log]# dmesg | grep -i usb[root@tecmint.com log]# dmesg | grep -i dma[root@tecmint.com log]# dmesg | grep -i tty[root@tecmint.com log]# dmesg | grep -i memory
[ 0.000000] Scanning 1 areas for low memory corruption[ 0.000000] initial memory mapped: [mem 0x00000000-0x01ffffff][ 0.000000] Base memory trampoline at [c009b000] 9b000 size 16384[ 0.000000] init_memory_mapping: [mem 0x00000000-0x000fffff][ 0.000000] init_memory_mapping: [mem 0x37800000-0x379fffff][ 0.000000] init_memory_mapping: [mem 0x34000000-0x377fffff][ 0.000000] init_memory_mapping: [mem 0x00100000-0x33ffffff][ 0.000000] init_memory_mapping: [mem 0x37a00000-0x37bfdfff][ 0.000000] Early memory node ranges[ 0.000000] PM: Registered nosave memory: [mem 0x0009f000-0x000effff][ 0.000000] PM: Registered nosave memory: [mem 0x000f0000-0x000fffff][ 0.000000] please try 'cgroup_disable=memory' option if you don't want memory cgroups[ 0.000000] Memory: 2003288K/2059928K available (6352K kernel code, 607K rwdata, 2640K rodata, 880K init, 908K bss, 56640K reserved, 1146920K highmem)[ 0.000000] virtual kernel memory layout:[ 0.004291] Initializing cgroup subsys memory[ 0.004609] Freeing SMP alternatives memory: 28K (c1a3e000 - c1a45000)[ 0.899622] Freeing initrd memory: 23616K (f51d0000 - f68e0000)[ 0.899813] Scanning for low memory corruption every 60 seconds[ 0.946323] agpgart-intel 0000:00:00.0: detected 32768K stolen memory[ 1.360318] Freeing unused kernel memory: 880K (c1962000 - c1a3e000)[ 1.429066] [drm] Memory usable by graphics device = 2048M
我們可以使用如下命令來清空dmesg的日志。該命令會清空dmesg環形緩沖區中的日志。但是你依然可以查看存儲在‘/var/log/dmesg’文件中的日志。你連接任何的設備都會產生dmesg日志輸出。
[root@tecmint.com log]# dmesg -c
在某些發行版中可以使用命令‘tail -f /var/log/dmesg’來實時監控dmesg的日志輸出。
[root@tecmint.com log]# watch "dmesg | tail -20"
結論:dmesg命令在系統dmesg記錄實時更改或產生的情況下是非常有用的。你可以使用man dmesg來獲取更多關于dmesg的信息。
看完上述內容,你們對Linux中怎么使用dmesg命令處理故障和收集系統信息有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。