{"id":12427,"date":"2019-03-26T23:41:35","date_gmt":"2019-03-26T23:41:35","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12427"},"modified":"2019-03-26T23:41:35","modified_gmt":"2019-03-26T23:41:35","slug":"7-dmesg-commands-for-troubleshooting-and-collecting-information-of-linux-systems","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/7-dmesg-commands-for-troubleshooting-and-collecting-information-of-linux-systems\/","title":{"rendered":"7 \u2018dmesg\u2019 Commands for Troubleshooting and Collecting Information of Linux Systems"},"content":{"rendered":"<p>The \u2018<b>dmesg<\/b>\u2018 command displays the messages from the kernel ring buffer. A system passes multiple runlevel from where we can get lot of information like system architecture, cpu, attached device, RAM etc. When computer boots up, a kernel (core of an operating system) is loaded into memory. During that period number of messages are being displayed where we can see hardware devices detected by kernel.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/commands-to-collect-system-and-hardware-information-in-linux\/\" target=\"_blank\" rel=\"noopener\">10 Linux Commands to Collect System and Hardware Information<\/a><\/p>\n<div id=\"attachment_7920\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/dmesg-Command-Examples.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7920\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/dmesg-Command-Examples.png\" alt=\"dmesg Command Examples\" width=\"425\" height=\"276\" aria-describedby=\"caption-attachment-7920\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-7920\" class=\"wp-caption-text\">dmesg Command Examples<\/p>\n<\/div>\n<p>The messages are very important in terms of diagnosing purpose in case of device failure. When we connect or disconnect hardware device on the system, with the help of dmesg command we come to know detected or disconnected information on the fly. The\u00a0<b>dmesg<\/b>\u00a0command is available on most\u00a0<b>Linux and Unix<\/b>\u00a0based Operating System.<\/p>\n<p>Let\u2019s throw some light on most famous tool called \u2018dmesg\u2019 command with their practical examples as discussed below. The exact syntax of dmesg as follows.<\/p>\n<pre># dmseg [options...]<\/pre>\n<h3>1. List all loaded Drivers in Kernel<\/h3>\n<p>We can use text-manipulation tools i.e. \u2018<b>more<\/b>\u2018, \u2018<b>tail<\/b>\u2018, \u2018<b>less<\/b>\u2018 or \u2018<b>grep<\/b>\u2018 with dmesg command. As output of dmesg log won\u2019t fit on a single page, using dmesg with pipe more or less command will display logs in a single page.<\/p>\n<pre>[root@tecmint.com ~]# dmesg | more\r\n[root@tecmint.com ~]# dmesg | less<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[    0.000000] Initializing cgroup subsys cpuset\r\n[    0.000000] Initializing cgroup subsys cpu\r\n[    0.000000] Initializing cgroup subsys cpuacct\r\n[    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 \r\n(Ubuntu 3.11.0-13.20-generic 3.11.6)\r\n[    0.000000] KERNEL supported cpus:\r\n[    0.000000]   Intel GenuineIntel\r\n[    0.000000]   AMD AuthenticAMD\r\n[    0.000000]   NSC Geode by NSC\r\n[    0.000000]   Cyrix CyrixInstead\r\n[    0.000000]   Centaur CentaurHauls\r\n[    0.000000]   Transmeta GenuineTMx86\r\n[    0.000000]   Transmeta TransmetaCPU\r\n[    0.000000]   UMC UMC UMC UMC\r\n[    0.000000] e820: BIOS-provided physical RAM map:\r\n[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable\r\n[    0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved\r\n[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000007dc08bff] usable\r\n[    0.000000] BIOS-e820: [mem 0x000000007dc08c00-0x000000007dc5cbff] ACPI NVS\r\n[    0.000000] BIOS-e820: [mem 0x000000007dc5cc00-0x000000007dc5ebff] ACPI data\r\n[    0.000000] BIOS-e820: [mem 0x000000007dc5ec00-0x000000007fffffff] reserved\r\n[    0.000000] BIOS-e820: [mem 0x00000000e0000000-0x00000000efffffff] reserved\r\n[    0.000000] BIOS-e820: [mem 0x00000000fec00000-0x00000000fed003ff] reserved\r\n[    0.000000] BIOS-e820: [mem 0x00000000fed20000-0x00000000fed9ffff] reserved\r\n[    0.000000] BIOS-e820: [mem 0x00000000fee00000-0x00000000feefffff] reserved\r\n[    0.000000] BIOS-e820: [mem 0x00000000ffb00000-0x00000000ffffffff] reserved\r\n[    0.000000] NX (Execute Disable) protection: active\r\n.....<\/pre>\n<p><b>Read Also<\/b>:\u00a0<a href=\"https:\/\/www.tecmint.com\/view-contents-of-file-in-linux\/\" target=\"_blank\" rel=\"noopener\">Manage Linux Files Effectively using commands head, tail and cat<\/a><\/p>\n<h3>2. List all Detected Devices<\/h3>\n<p>To discover which hard disks has been detected by kernel, you can search for the keyword \u201c<strong>sda<\/strong>\u201d along with \u201c<strong>grep<\/strong>\u201d like shown below.<\/p>\n<pre>[root@tecmint.com ~]# dmesg | grep sda\r\n\r\n[    1.280971] sd 2:0:0:0: [<b>sda<\/b>] 488281250 512-byte logical blocks: (250 GB\/232 GiB)\r\n[    1.281014] sd 2:0:0:0: [<b>sda<\/b>] Write Protect is off\r\n[    1.281016] sd 2:0:0:0: [<b>sda<\/b>] Mode Sense: 00 3a 00 00\r\n[    1.281039] sd 2:0:0:0: [<b>sda<\/b>] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA\r\n[    1.359585]  <b>sda<\/b>: <b>sda<\/b>1 <b>sda<\/b>2 &lt; <b>sda<\/b>5 <b>sda<\/b>6 <b>sda<\/b>7 <b>sda<\/b>8 &gt;\r\n[    1.360052] sd 2:0:0:0: [<b>sda<\/b>] Attached SCSI disk\r\n[    2.347887] EXT4-fs (<b>sda<\/b>1): mounted filesystem with ordered data mode. Opts: (null)\r\n[   22.928440] Adding 3905532k swap on \/dev\/<b>sda<\/b>6.  Priority:-1 extents:1 across:3905532k FS\r\n[   23.950543] EXT4-fs (<b>sda<\/b>1): re-mounted. Opts: errors=remount-ro\r\n[   24.134016] EXT4-fs (<b>sda<\/b>5): mounted filesystem with ordered data mode. Opts: (null)\r\n[   24.330762] EXT4-fs (<b>sda<\/b>7): mounted filesystem with ordered data mode. Opts: (null)\r\n[   24.561015] EXT4-fs (<b>sda<\/b>8): mounted filesystem with ordered data mode. Opts: (null)<\/pre>\n<p><strong>NOTE<\/strong>: The \u2018sda\u2019 first SATA hard drive, \u2018sdb\u2019 is the second SATA hard drive and so on. Search with \u2018hda\u2019 or \u2018hdb\u2019 in the case of IDE hard drive.<\/p>\n<h3>3. Print Only First 20 Lines of Output<\/h3>\n<p>The \u2018head\u2019 along with dmesg will show starting lines i.e. \u2018dmesg | head -20\u2019 will print only 20 lines from the starting point.<\/p>\n<pre>[root@tecmint.com ~]# dmesg | head  -20\r\n\r\n[    0.000000] Initializing cgroup subsys cpuset\r\n[    0.000000] Initializing cgroup subsys cpu\r\n[    0.000000] Initializing cgroup subsys cpuacct\r\n[    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)\r\n[    0.000000] KERNEL supported cpus:\r\n[    0.000000]   Intel GenuineIntel\r\n[    0.000000]   AMD AuthenticAMD\r\n[    0.000000]   NSC Geode by NSC\r\n[    0.000000]   Cyrix CyrixInstead\r\n[    0.000000]   Centaur CentaurHauls\r\n[    0.000000]   Transmeta GenuineTMx86\r\n[    0.000000]   Transmeta TransmetaCPU\r\n[    0.000000]   UMC UMC UMC UMC\r\n[    0.000000] e820: BIOS-provided physical RAM map:\r\n[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable\r\n[    0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved\r\n[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000007dc08bff] usable\r\n[    0.000000] BIOS-e820: [mem 0x000000007dc08c00-0x000000007dc5cbff] ACPI NVS\r\n[    0.000000] BIOS-e820: [mem 0x000000007dc5cc00-0x000000007dc5ebff] ACPI data\r\n[    0.000000] BIOS-e820: [mem 0x000000007dc5ec00-0x000000007fffffff] reserved<\/pre>\n<h3>4. Print Only Last 20 Lines of Output<\/h3>\n<p>The \u2018tail\u2019 along with dmesg command will print only 20 last lines, this is useful in case we insert removable device.<\/p>\n<pre>[root@tecmint.com ~]# dmesg | tail -20\r\n\r\nparport0: PC-style at 0x378, irq 7 [PCSPP,TRISTATE]\r\nppdev: user-space parallel port driver\r\nEXT4-fs (sda1): mounted filesystem with ordered data mode\r\nAdding 2097144k swap on \/dev\/sda2.  Priority:-1 extents:1 across:2097144k\r\nreadahead-disable-service: delaying service auditd\r\nip_tables: (C) 2000-2006 Netfilter Core Team\r\nnf_conntrack version 0.5.0 (16384 buckets, 65536 max)\r\nNET: Registered protocol family 10\r\nlo: Disabled Privacy Extensions\r\ne1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None\r\nSlow work thread pool: Starting up\r\nSlow work thread pool: Ready\r\nFS-Cache: Loaded\r\nCacheFiles: Loaded\r\nCacheFiles: Security denies permission to nominate security context: error -95\r\neth0: no IPv6 routers present\r\ntype=1305 audit(1398268784.593:18630): audit_enabled=0 old=1 auid=4294967295 ses=4294967295 res=1\r\nreadahead-collector: starting delayed service auditd\r\nreadahead-collector: sorting\r\nreadahead-collector: finished<\/pre>\n<h3>5. Search Detected Device or Particular String<\/h3>\n<p>It\u2019s difficult to search particular string due to length of dmesg output. So, filter the lines with are having string like \u2018<strong>usb<\/strong>\u2018 \u2018<strong>dma<\/strong>\u2018 \u2018<strong>tty<\/strong>\u2018 and \u2018<strong>memory<\/strong>\u2018 etc. The \u2018-i\u2019 option instruct to\u00a0<a href=\"https:\/\/www.tecmint.com\/12-practical-examples-of-linux-grep-command\/\" target=\"_blank\" rel=\"noopener\">grep command<\/a>\u00a0to ignore the case (upper or lower case letters).<\/p>\n<pre>[root@tecmint.com log]# dmesg | grep -i usb\r\n[root@tecmint.com log]# dmesg | grep -i dma\r\n[root@tecmint.com log]# dmesg | grep -i tty\r\n[root@tecmint.com log]# dmesg | grep -i memory<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[    0.000000] Scanning 1 areas for low <b>memory<\/b> corruption\r\n[    0.000000] initial <b>memory<\/b> mapped: [mem 0x00000000-0x01ffffff]\r\n[    0.000000] Base <b>memory<\/b> trampoline at [c009b000] 9b000 size 16384\r\n[    0.000000] init_<b>memory<\/b>_mapping: [mem 0x00000000-0x000fffff]\r\n[    0.000000] init_<b>memory<\/b>_mapping: [mem 0x37800000-0x379fffff]\r\n[    0.000000] init_<b>memory<\/b>_mapping: [mem 0x34000000-0x377fffff]\r\n[    0.000000] init_<b>memory<\/b>_mapping: [mem 0x00100000-0x33ffffff]\r\n[    0.000000] init_<b>memory<\/b>_mapping: [mem 0x37a00000-0x37bfdfff]\r\n[    0.000000] Early <b>memory<\/b> node ranges\r\n[    0.000000] PM: Registered nosave <b>memory<\/b>: [mem 0x0009f000-0x000effff]\r\n[    0.000000] PM: Registered nosave <b>memory<\/b>: [mem 0x000f0000-0x000fffff]\r\n[    0.000000] please try 'cgroup_disable=<b>memory<\/b>' option if you don't want <b>memory<\/b> cgroups\r\n[    0.000000] <b>Memory<\/b>: 2003288K\/2059928K available (6352K kernel code, 607K rwdata, 2640K rodata, 880K init, 908K bss, 56640K reserved, 1146920K highmem)\r\n[    0.000000] virtual kernel <b>memory<\/b> layout:\r\n[    0.004291] Initializing cgroup subsys <b>memory<\/b>\r\n[    0.004609] Freeing SMP alternatives <b>memory<\/b>: 28K (c1a3e000 - c1a45000)\r\n[    0.899622] Freeing initrd <b>memory<\/b>: 23616K (f51d0000 - f68e0000)\r\n[    0.899813] Scanning for low <b>memory<\/b> corruption every 60 seconds\r\n[    0.946323] agpgart-intel 0000:00:00.0: detected 32768K stolen <b>memory<\/b>\r\n[    1.360318] Freeing unused kernel <b>memory<\/b>: 880K (c1962000 - c1a3e000)\r\n[    1.429066] [drm] <b>Memory<\/b> usable by graphics device = 2048M<\/pre>\n<h3>6. Clear dmesg Buffer Logs<\/h3>\n<p>Yes, we can clear dmesg logs if required with below command. It will clear dmesg ring buffer message logs till you executed the command below. Still you can view logs stored in \u2018<strong>\/var\/log\/dmesg<\/strong>\u2018 files. If you connect any device will generate dmesg output.<\/p>\n<pre>[root@tecmint.com log]# dmesg -c<\/pre>\n<h3>7. Monitoring dmesg in Real Time<\/h3>\n<p>Some distro allows command \u2018tail -f \/var\/log\/dmesg\u2019 as well for real time dmesg monitoring.<\/p>\n<pre>[root@tecmint.com log]# watch \"dmesg | tail -20\"<\/pre>\n<p><strong>Conclusion<\/strong>: The dmesg command is useful as dmesg records all the system changes done or occur in real time. As always you can\u00a0<b>man dmesg<\/b>\u00a0to get more information.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/dmesg-commands\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The \u2018dmesg\u2018 command displays the messages from the kernel ring buffer. A system passes multiple runlevel from where we can get lot of information like system architecture, cpu, attached device, RAM etc. When computer boots up, a kernel (core of an operating system) is loaded into memory. During that period number of messages are being &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/7-dmesg-commands-for-troubleshooting-and-collecting-information-of-linux-systems\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;7 \u2018dmesg\u2019 Commands for Troubleshooting and Collecting Information of Linux Systems&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12427","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12427"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12427\/revisions"}],"predecessor-version":[{"id":12428,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12427\/revisions\/12428"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}