C语言再学习 -- dmesg 命令
dmesg 這個命令,Linux下用的還是比較多的?,F在來詳細看一下:
Linux dmesg命令用于顯示開機信息。
kernel會將開機信息存儲在ring buffer中。您若是開機時來不及查看信息,可利用dmesg來查看。開機信息亦保存在/var/log目錄中,名稱為dmesg的文件里。
一、語法
dmesg [-cn][-s <緩沖區大小>]
二、選項
-c :顯示信息后,清除ring buffer中的內容。
-s <緩沖區大小>:預設置為8196,剛好等于ring buffer的大小。
-n :設置記錄信息的層級。
三、實例
root@dm368-evm:/# dmesg >Bad block table found at page 262080, version 0x01 Bad block table found at page 262016, version 0x01 nand_bbt: ECC error while reading bad block table nand_read_bbt: Bad block at 0x00000ff00000 nand_read_bbt: Bad block at 0x00000ff20000 nand_read_bbt: Bad block at 0x00000ff40000 nand_read_bbt: Bad block at 0x00000ff60000 nand_read_bbt: Bad block at 0x00000ff80000 nand_read_bbt: Bad block at 0x00000ffa0000 nand_read_bbt: Bad block at 0x00000ffc0000 nand_read_bbt: Bad block at 0x00000ffe0000 Creating 5 MTD partitions on "davinci_nand.0": 0x000000000000-0x0000003c0000 : "bootloader" 0x0000003c0000-0x000000400000 : "params" 0x000000400000-0x000000820000 : "kernel" 0x000000820000-0x000008820000 : "filesystem" 0x000008820000-0x000020000000 : "zslf" davinci_nand davinci_nand.0: controller rev. 2.3 UBI: attaching mtd3 to ubi0 UBI: physical eraseblock size: 131072 bytes (128 KiB) UBI: logical eraseblock size: 126976 bytes UBI: smallest flash I/O unit: 2048 UBI: VID header offset: 2048 (aligned 2048) UBI: data offset: 4096 UBI: attached mtd3 to ubi0 UBI: MTD device name: "filesystem" UBI: MTD device size: 128 MiB UBI: number of good PEBs: 1024 UBI: number of bad PEBs: 0 UBI: max. allowed volumes: 128 UBI: wear-leveling threshold: 4096 UBI: number of internal volumes: 1 UBI: number of user volumes: 1 UBI: available PEBs: 5 UBI: total number of reserved PEBs: 1019 UBI: number of PEBs reserved for bad PEB handling: 10 UBI: max/mean erase counter: 20/11 UBI: image sequence number: 0 UBI: background thread "ubi_bgt0d" started, PID 343 PPP generic driver version 2.4.2 PPP Deflate Compression module registered PPP BSD Compression module registered PPP MPPE Compression module registered NET: Registered protocol family 24 tun: Universal TUN/TAP device driver, 1.6 tun: (C) 1999-2004 Max Krasnyansky <maxk@qualcomm.com> console [netcon0] enabled netconsole: network logging started Initializing USB Mass Storage driver... usbcore: registered new interface driver usb-storage USB Mass Storage support registered. usbcore: registered new interface driver usbserial USB Serial support registered for generic usbcore: registered new interface driver usbserial_generic usbserial: USB Serial Driver core USB Serial support registered for GSM modem (1-port) usbcore: registered new interface driver option option: v0.7.2:USB Driver for GSM modems usbcore: registered new interface driver usbtest rtc-ds1307 1-0068: rtc core: registered ds1339 as rtc0 i2c /dev entries driver Linux video capture interface: v2.00 ths7303 1-002c: chip found @ 0x58 (DaVinci I2C adapter) ths7303 1-002c: ths7303 write failed ths7303: probe of 1-002c failed with error -121 vpfe_init vpfe-capture: vpss clock vpss_master enabled vpfe-capture vpfe-capture: v4l2 device registered vpfe-capture vpfe-capture: video device registered dm365evm_enable_pca9543a dm365evm_enable_pca9543a, status = -121 EVM: switch to HD imager video input mt9p031 1-005d: Detected a MT9P031 chip ID 1801 mt9p031 1-005d: mt9p031 1-005d decoder driver registered !! vpfe-capture vpfe-capture: v4l2 sub device mt9p031 registered vpfe_register_ccdc_device: DM365 ISIF DM365 ISIF is registered with vpfe. af major#: 250, minor# 0 AF Driver initialized aew major#: 249, minor# 0 AEW Driver initialized ###### osd_init ###### ### VPBE OSD DRIVER INIT ### <davinci_display_init> Trying to register davinci display video device. layer=c112d000,layer->video_dev=c112d170 Trying to register davinci display video device. layer=c112d400,layer->video_dev=c112d570 davinci_init:DaVinci V4L2 Display Driver V1.0 loaded </davinci_init> watchdog watchdog: heartbeat 60 sec davinci_mmc davinci_mmc.0: Using DMA, 4-bit mode Advanced Linux Sound Architecture Driver Version 1.0.21. No device for DAI tlv320aic3x No device for DAI davinci-i2s asoc: tlv320aic3x <-> davinci-i2s mapping ok ALSA device list:#0: DaVinci EVM (tlv320aic3x) TCP cubic registered NET: Registered protocol family 17 Clocks: disable unused mmcsd1 Clocks: disable unused spi0 Clocks: disable unused spi1 Clocks: disable unused spi2 Clocks: disable unused spi3 Clocks: disable unused spi4 Clocks: disable unused pwm0 Clocks: disable unused pwm1 Clocks: disable unused pwm2 Clocks: disable unused pwm3 Clocks: disable unused timer1 Clocks: disable unused timer3 Clocks: disable unused emac Clocks: disable unused voice_codec Clocks: disable unused rto Clocks: disable unused mjcp davinci_emac_probe: using random MAC addr: 32:be:8d:46:68:be emac-mii: probed rtc-ds1307 1-0068: setting system clock to 2015-12-05 11:04:18 UTC (1449313458) UBIFS: mounted UBI device 0, volume 0, name "rootfs" UBIFS: file system size: 126341120 bytes (123380 KiB, 120 MiB, 995 LEBs) UBIFS: journal size: 6348800 bytes (6200 KiB, 6 MiB, 50 LEBs) UBIFS: media format: w4/r0 (latest is w4/r0) UBIFS: default compressor: lzo UBIFS: reserved for root: 4952683 bytes (4836 KiB) VFS: Mounted root (ubifs filesystem) on device 0:14. Freeing init memory: 144K udev: starting version 141 eth0: attached PHY driver [LXT971] (mii_bus:phy_addr=1:01, id=1378e2) CMEMK module: built on Mar 24 2011 at 16:58:03Reference Linux version 2.6.32File /sdk/build/DVSDK_4_02/4_02_00_06/arago-install/arago-tmp/work/dm368-evm-none-linux-gnueabi/ti-linuxutils-1_2_26_01_02-r52d/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/cmem/src/module/cmemk.c allocated heap buffer 0xc7000000 of size 0x4400000 heap fallback enabled - will try heap if pool buffer is not available CMEM Range Overlaps Kernel Physical - allowing overlap CMEM phys_start (0x1000) overlaps kernel (0x80000000 -> 0x83000000) cmemk initialized PHY: 1:01 - Link is Up - 100/Full IRQK module: built on Mar 24 2011 at 16:58:17Reference Linux version 2.6.32File /sdk/build/DVSDK_4_02/4_02_00_06/arago-install/arago-tmp/work/dm368-evm-none-linux-gnueabi/ti-linuxutils-1_2_26_01_02-r52d/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/irq/src/module/irqk.c irqk initialized EDMAK module: built on Mar 24 2011 at 16:58:11Reference Linux version 2.6.32File /sdk/build/DVSDK_4_02/4_02_00_06/arago-install/arago-tmp/work/dm368-evm-none-linux-gnueabi/ti-linuxutils-1_2_26_01_02-r52d/linuxutils_2_26_01_02/packages/ti/sdo/linuxutils/edma/src/module/edmak.c ###### output_store ###### ###### davinci_get_cur_encoder ###### <vpbe_encoder_enumoutput> </vpbe_encoder_enumoutput> <vpbe_encoder_enumoutput> </vpbe_encoder_enumoutput> VPBE Encoder de-initialized ###### vpbe_encoder_initialize ###### ###### output is COMPOSITE,outindex is 0 ###### ###### vpbe_encoder_setoutput ###### <vpbe_encoder_setoutput> Setting output to Composite Start of vpbe_encoder_setmode.. ###### dm365 = 1 ###### ###### mode_info->std is 1 ###### ###### mode is NTSC ###### </vpbe_encoder_setmode> </vpbe_encoder_setoutput> VPBE Encoder initialized ###### 22VPBE Encoder initialized ###### ###### vpbe_encoder_setoutput ###### <vpbe_encoder_setoutput> Setting output to Component Video Start of vpbe_encoder_setmode.. ###### dm365 = 1 ###### ###### mode_info->std is 1 ###### ###### mode is 480P-60 ###### </vpbe_encoder_setmode> </vpbe_encoder_setoutput> <vpbe_encoder_getmode> <vpbe_encoder_getmode/> ###### davinci_enc_set_output : next davinci_enc_set_mode_platform ###### ###### davinci_enc_set_mode_platform : next davinci_enc_priv_setmode ###### ###### output_show ###### ###### davinci_enc_get_output ###### ###### davinci_get_cur_encoder ###### <vpbe_encoder_getoutput> </vpbe_encoder_getoutput> ###### mode_store ###### ###### davinci_enc_get_mode ###### ###### davinci_get_cur_encoder ###### <vpbe_encoder_getmode> <vpbe_encoder_getmode/> ###### davinci_enc_set_mode ###### ###### davinci_get_cur_encoder ###### Start of vpbe_encoder_setmode.. ###### dm365 = 1 ###### ###### mode_info->std is 1 ###### ###### mode is 576P-50 ###### </vpbe_encoder_setmode> <vpbe_encoder_getmode> <vpbe_encoder_getmode/> ###### davinci_enc_set_mode : next davinci_enc_set_mode ###### ###### davinci_enc_set_mode_platform : next davinci_enc_priv_setmode ###### ###### mode_show ###### ###### davinci_enc_get_mode ###### ###### davinci_get_cur_encoder ###### <vpbe_encoder_getmode> <vpbe_encoder_getmode/> ###### davinci_enc_get_mode ###### ###### davinci_get_cur_encoder ###### <vpbe_encoder_getmode> <vpbe_encoder_getmode/> ###### davinci_enc_get_mode ###### ###### davinci_get_cur_encoder ###### <vpbe_encoder_getmode> <vpbe_encoder_getmode/> ###### davinci_enc_set_mode ###### ###### davinci_get_cur_encoder ###### Start of vpbe_encoder_setmode.. ###### dm365 = 1 ###### ###### mode_info->std is 1 ###### ###### mode is 576P-50 ###### </vpbe_encoder_setmode> <vpbe_encoder_getmode> <vpbe_encoder_getmode/> ###### davinci_enc_set_mode : next davinci_enc_set_mode ###### ###### davinci_enc_set_mode_platform : next davinci_enc_priv_setmode ###### ###### davinci_enc_get_mode ###### ###### davinci_get_cur_encoder ###### <vpbe_encoder_getmode> <vpbe_encoder_getmode/> ###### davinci_enc_get_mode ###### ###### davinci_get_cur_encoder ###### <vpbe_encoder_getmode> <vpbe_encoder_getmode/> ###### davinci_enc_get_mode ###### ###### davinci_get_cur_encoder ###### <vpbe_encoder_getmode> <vpbe_encoder_getmode/> davinci_resizer davinci_resizer.2: RSZ_G_CONFIG:0:1:124 davinci_previewer davinci_previewer.2: ipipe_set_preview_config davinci_previewer davinci_previewer.2: ipipe_set_preview_config vpfe-capture vpfe-capture: IPIPE Chained vpfe-capture vpfe-capture: Resizer present dm365evm_enable_pca9543a dm365evm_enable_pca9543a, status = -121 EVM: switch to HD imager video input ######vpfe_dev->current_subdev->is_camera. -----Exposure time = 2f2############ v4l2_device_call_until_err sdinfo->grp_id : 4. -----Exposure time = 2f2 vpfe-capture vpfe-capture: width = 1280, height = 720, bpp = 1 vpfe-capture vpfe-capture: adjusted width = 1280, height = 720, bpp = 1, bytesperline = 1280, sizeimage = 1382400 vpfe-capture vpfe-capture: width = 1280, height = 720, bpp = 1 vpfe-capture vpfe-capture: adjusted width = 1280, height = 720, bpp = 1, bytesperline = 1280, sizeimage = 1382400 ipipe_set_resizer, resizer - A enabled四、與管道一起使用
- 參看:Linux系統中‘dmesg’命令處理故障和收集系統信息的7種用法
(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 .....2、 列出所有被檢測到的硬件
要顯示所有被內核檢測到的硬盤設備,你可以使用‘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’關鍵詞。
3、只輸出dmesg命令的前20行日志
在‘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] reserved4、只輸出dmesg命令最后20行日志
在‘dmesg’命令后跟隨‘tail’命令(‘ dmesg | tail -20’)來輸出‘dmesg’命令的最后20行日志,當你插入可移動設備時它是非常有用的。
[root@tecmint.com ~]# dmesg | tail -20parport0: PC-style at 0x378, irq 7 [PCSPP,TRISTATE] ppdev: user-space parallel port driver EXT4-fs (sda1): mounted filesystem with ordered data mode Adding 2097144k swap on /dev/sda2. Priority:-1 extents:1 across:2097144k readahead-disable-service: delaying service auditd ip_tables: (C) 2000-2006 Netfilter Core Team nf_conntrack version 0.5.0 (16384 buckets, 65536 max) NET: Registered protocol family 10 lo: Disabled Privacy Extensions e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None Slow work thread pool: Starting up Slow work thread pool: Ready FS-Cache: Loaded CacheFiles: Loaded CacheFiles: Security denies permission to nominate security context: error -95 eth0: no IPv6 routers present type=1305 audit(1398268784.593:18630): audit_enabled=0 old=1 auid=4294967295 ses=4294967295 res=1 readahead-collector: starting delayed service auditd readahead-collector: sorting readahead-collector: finished5、搜索包含特定字符串的被檢測到的硬件
由于‘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 = 2048M6、清空dmesg緩沖區日志
我們可以使用如下命令來清空dmesg的日志。該命令會清空dmesg環形緩沖區中的日志。但是你依然可以查看存儲在‘/var/log/dmesg’文件中的日志。你連接任何的設備都會產生dmesg日志輸出。
[root@tecmint.com log]# dmesg -c7、實時監控dmesg日志輸出
在某些發行版中可以使用命令‘tail -f /var/log/dmesg’來實時監控dmesg的日志輸出。
[root@tecmint.com log]# watch "dmesg | tail -20"結論: dmesg命令在系統dmesg記錄實時更改或產生的情況下是非常有用的。你可以使用man dmesg來獲取更多關于dmesg的信息。
總結
以上是生活随笔為你收集整理的C语言再学习 -- dmesg 命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 互联网晚报 | 4月17日 星期天 |
- 下一篇: Oracle存储过程快速入门