Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use dmesg command in Linux to deal with faults and collect system information

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to use the dmesg command to deal with faults and collect system information in Linux. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

1. List all drivers loaded into the kernel

We can use things such as' more'. The 'tail',' less'or 'grep' word processing tool' handles the output of the 'dmesg' command. Since the output of the dmesg log is not suitable for full display on one page, we use a pipe to send its output to the more or less command for single-page display.

[root@tecmint.com ~] # dmesg | more [root@tecmint.com ~] # dmesg | less output [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. List all detected hardware

To display all hard disk devices detected by the kernel, you can search for the sda' keyword using the 'grep' command' as follows:

[root@tecmint.com ~] # dmesg | grep sda [1.280971] sd 2lv 0VO sd 0: [sda] 488281250 512-byte logical blocks: (250GB/232 GiB) [1.281014] sd 2VOV 0R0: [sda] Write Protect is off [1.281016] sd 2VOV 0VOLO: [sda] Mode Sense: 00 3a 00 [1.281039] sd 2Rl0: [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 Attached SCSI disk 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)

Note 'sda'' for * SATA hard disk, and 'sdb' for the second SATA hard disk. If you want to view the IDE hard drive search for 'hda'' or 'hdb'' keywords.

3. Output only the first 20 lines of the dmesg command log

Follow the 'dmesg' command' head' command to display the first few lines, and the 'dmesg | head-20' command will display the first 20 lines.

[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. Only output dmesg command * 20 lines of log

Follow the 'dmesg' command' tail' command ('dmesg | tail-20') to output 20 lines of logs of the 'dmesg' command, which is very useful when you plug in a removable device.

[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): audit_enabled=0 old=1 auid=4294967295 ses=4294967295 res=1readahead-collector: starting delayed service auditdreadahead-collector: sortingreadahead-collector: finished5. Search for detected hardware that contains a specific string

Because the output of the 'dmesg' command is simply too long, it is very difficult to search for a particular string in it. Therefore, it is necessary to filter out some log lines that contain strings such as' usb' 'dma'' tty' 'memory'. The'- i' option of the grep command indicates that case is ignored.

[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 output [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 0000V 00.0: detected 32768K stolen memory [1.360318] Freeing unused kernel memory: 880K (c1962000-c1a3e000) [1 .429066] [drm] Memory usable by graphics device = 2048M6. Clear the dmesg buffer log

We can use the following command to empty the dmesg log. This command clears the logs in the dmesg ring buffer. But you can still view the logs stored in the'/ var/log/dmesg' file. Any device you connect will generate dmesg log output.

[root@tecmint.com log] # dmesg-c7. Real-time monitoring dmesg log output

In some distributions, you can use the command 'tail-f / var/log/dmesg' to monitor the log output of dmesg in real time.

[root@tecmint.com log] # watch "dmesg | tail-20"

Conclusion: the dmesg command is very useful when the system dmesg records real-time changes or generation. You can use man dmesg to get more information about dmesg.

After reading the above, do you have any further understanding of how to use the dmesg command in Linux to handle faults and collect system information? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report