{"id":381438,"date":"2021-12-15T16:02:18","date_gmt":"2021-12-15T13:02:18","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-use-lsmod-in-linux-with-a-practical-example-cloudsavvy-it\/"},"modified":"2021-12-15T16:02:18","modified_gmt":"2021-12-15T13:02:18","slug":"how-to-use-lsmod-in-linux-with-a-practical-example-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-use-lsmod-in-linux-with-a-practical-example-cloudsavvy-it\/","title":{"rendered":"#How to Use lsmod in Linux (With a Practical Example) \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a33a126cc741\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a33a126cc741\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-lsmod-in-linux-with-a-practical-example-cloudsavvy-it\/#What_Is_lsmod\" >What Is lsmod?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-lsmod-in-linux-with-a-practical-example-cloudsavvy-it\/#lsmod_First_Looks\" >lsmod: First Looks<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-lsmod-in-linux-with-a-practical-example-cloudsavvy-it\/#Diving_Deeper_With_modinfo\" >Diving Deeper With modinfo<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-lsmod-in-linux-with-a-practical-example-cloudsavvy-it\/#Wrapping_up\" >Wrapping up<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Use lsmod in Linux (With a Practical Example) \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"How to Use lsmod in Linux (With a Practical Example)\" width=\"1400\" height=\"600\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The Linux Kernel is a mystery to most, but it need not be! Welcome to the exciting world of lsmod, a tool that lets you peek at what modules the Kernel is using, and more!<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_Is_lsmod\"><\/span>What Is <i>lsmod<\/i>?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To explain <code>lsmod<\/code>, the tool which allows one to list modules in the Linux Kernel, one first has to understand what a module is. A Linux module is a modular piece of code (running in a compiled format) that can be loaded or unloaded from the Linux kernel at will. The main advantage of using such modules is their modularity and granularity of them.<\/p>\n<p>You can think about Kernel modules as plugins in other software. Whenever you need a specific \u2013 less common, or not universal \u2013 functionality, it will be available as a plugin, or in the case of the Linux Kernel as a module. There is little difference between a plugin in other software and Linux Kernel modules. However, the level at which they operate is much closer to the hardware and core operating software, rather than at the end of the stack at the user level.<\/p>\n<p>For example, your graphics card driver \u2013 especially if you are using NVidia drivers \u2013 is loaded as a Kernel module. When you install the driver, a kernel module is configured and loaded (possibly on the next restart of your system).<\/p>\n<p>Coming back to <code>lsmod<\/code>, which should be included in the default installation of your Linux operating system, this tool will list an overview of kernel modules that are currently available.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"lsmod_First_Looks\"><\/span><i>lsmod<\/i>: First Looks<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Interestingly, <code>lsmod<\/code> is a tool which renders the contents of the (virtual) <code>\/proc\/modules<\/code> file into more human readable content.<\/p>\n<p>The <code>\/proc\/modules<\/code> file is a 0-byte virtual file which, when viewed with for example <code>cat<\/code> or <code>vi<\/code>, will contain (or better <i>render<\/i>) a list of modules currently available for the Linux Kernel on the system where <code>lsmod<\/code> is being executed.<\/p>\n<p>Let\u2019s start by checking the contents of the <code>\/proc\/modules<\/code> file for the presence of a AHCI (Advanced Host Controller Interface) Linux Kernel module:<\/p>\n<pre>cat \/proc\/modules | grep ahci&#13;\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14736\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/ba6beb7a.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Viewing the contents of \/proc\/modules\" width=\"374\" height=\"69\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Here we use <code>cat<\/code> to display (<i>render<\/i>) the contents of <code>\/proc\/modules<\/code>, and subsequently use <code>grep<\/code> to grep for the AHCI module. Note that we did not specify the <code>-i<\/code> option (which would do a case-insensitive search) to <code>grep<\/code>, as the full list of modules <code>\/proc\/modules<\/code> is lowercase only.<\/p>\n<p>We can see from the output provided what AHCI Linux Kernel modules are currently available. Otherwise, the output looks a bit cryptic and not very de<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">script<\/a>ive. Let\u2019s try <code>lsmod<\/code> instead now.<\/p>\n<pre>lsmod | grep -E '^Module|ahci'&#13;\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14737\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/079f4fb5.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using lsmod to list the contents of \/proc\/modules in a better format and grepping for a particular module\" width=\"332\" height=\"84\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Here we used <code>lsmod<\/code>, a tool with no options, and used <code>grep<\/code> to grab multiple outcomes of interest. The <code>-E<\/code> option to grep allows us to make a selector\/selection list (strings) of items we want to see, all separated by one or more pipe symbol (<code>|<\/code>).<\/p>\n<p>Here we thus are looking for any <code>ahci<\/code> occurrences (in the second selector\/selection string), and any <code>^Module<\/code> occurrences (in the first selector\/selection string), where the <code>^<\/code> is a regular expression (applicable to the first selector only), selecting the <i>start of a line<\/i>, indicating we want to only see results where the <i>start of the line<\/i> is im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>tely followed by \u2018Module\u2019 and this would be our first header line.<\/p>\n<p>We see the output now nicely rendered; the first line (which our <code>grep<\/code> command included as thanks to the <code>^Module<\/code> selector) and the second and third line listing the <code>ahci<\/code> modules which our <code>grep<\/code> selected due to the second selector.<\/p>\n<p>The header column outputs tell us what each column contains; the first column the module name (<i>Module<\/i>), the second the size is bytes (<i>Size<\/i>), and the third column provides a <i>reference count<\/i> (<i>Used by<\/i>), or in other words how many times a module is referenced (which can perhaps vaguely be translated to <i>used<\/i>) by the kernel.<\/p>\n<p>If the reference count in the third column is zero, it means that while the module is available <i>\u201cin\u201d<\/i>\/to the Kernel, it is not currently being used.<\/p>\n<p>Tip: if you ever see <code>-2<\/code> in the output of <code>lsmod<\/code>, you may want to checkout <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/unix.stackexchange.com\/questions\/269500\/lsmod-shows-2-in-the-used-by-column\">lsmod shows -2 in the \u201cUsed by\u201d column<\/a> on Stackexchange.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Diving_Deeper_With_modinfo\"><\/span>Diving Deeper With <i>modinfo<\/i><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Whilst the <code>lsmod<\/code> tool has no options itself, we can use a another utility in combination with <i>lsmod<\/i> to discover more information: <code>modinfo<\/code>.<\/p>\n<pre>modinfo ahci -F 'description'&#13;\nmodinfo ahci -F 'author'&#13;\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-14739 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/7134f8f5.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using the modinfo tool with the -F (field) option to select specific fields only\" width=\"280\" height=\"82\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Here we used the <code>modinfo<\/code> command to find out more information about the <code>ahci<\/code> Linux Kernel module. In particular, we used the <code>-F<\/code> option to <code>modinfo<\/code> to select a specific field for which we would like to learn it\u2019s contents. Note that if you execute <code>modinfo ahci<\/code> without any options, you will see a full list of all available information on the <code>ahci<\/code> Kernel module. This is output is quite verbose as it includes signing key data etc.<\/p>\n<p>We could have also used <code>grep<\/code> similarly as we did earlier to select both pieces of information in a single command. To do so, we use <code>modinfo ahci | grep -E 'description|author'<\/code>, which renders the same output of two lines, albeit directly under each other.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-14738 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/75c168b6.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Using the modinfo tool in combination with grep to select multiple fields at once\" width=\"465\" height=\"67\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Note also that one could again use the regular expression <code>'<\/code> to select only the output strings which start at the beginning of the line (for both fields being searched for), i.e. <code>modinfo ahci | grep -E '^description|^author'<\/code><\/p>\n<p>In contrast to\u00a0<code>lsmod<\/code>, <code>modinfo<\/code>\u00a0has some further options which may of interest. Checkout\u00a0<code>man modinfo<\/code>to see all available options.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Wrapping_up\"><\/span>Wrapping up<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In this article, we explored the option-less <code>lsmod<\/code> tool and the handy output it provides us with, showing us which Linux Kernel modules are available and how many times each such Kernel Module is currently being referenced (<i>\u201cused\u201d<\/i>) by the Kernel. We also looked at how to obtain more information about a specific module by using the <code>modinfo<\/code> command in Linux. We also looked at how we can use <code>grep -E<\/code> to obtain two pieces of information at once by using multiple selection strings to scan for.<\/p>\n<p>If you enjoyed reading this article, have a look at our How to Use ltrace to Trace Library Calls and How to Work with Shared Object (Library) Dependencies in Linux articles. <strong>Enjoy!<\/strong>\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/14735\/how-to-use-lsmod-in-linux-with-a-practical-example\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Use lsmod in Linux (With a Practical Example) \u2013 CloudSavvy IT&#8221; The Linux Kernel is a mystery to most, but it need not be! Welcome to the exciting world of lsmod, a tool that lets you peek at what modules the Kernel is using, and more! What Is lsmod? To explain lsmod, the&#8230;<\/p>\n","protected":false},"author":1,"featured_media":381439,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-381438","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/381438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=381438"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/381438\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/381439"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=381438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=381438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=381438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}