<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: orhun</title>
    <description>The latest articles on DEV Community by orhun (@orhun).</description>
    <link>https://dev.to/orhun</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F315784%2F9170b857-f634-4be3-b541-d0a12313984c.png</url>
      <title>DEV Community: orhun</title>
      <link>https://dev.to/orhun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/orhun"/>
    <language>en</language>
    <item>
      <title>Kmon! Let's manage the Linux kernel modules! 🐧💻</title>
      <dc:creator>orhun</dc:creator>
      <pubDate>Thu, 02 Apr 2020 11:29:46 +0000</pubDate>
      <link>https://dev.to/orhun/kmon-let-s-manage-the-linux-kernel-modules-58mh</link>
      <guid>https://dev.to/orhun/kmon-let-s-manage-the-linux-kernel-modules-58mh</guid>
      <description>&lt;p&gt;Unfortunately, it's common to use a technology without knowing the inner workings of it. However, having a good grasp on the specific details of it might help with various situations like fixing a bug or adding new features to it. Especially if you're a developer/engineer.&lt;/p&gt;

&lt;p&gt;I've been using &lt;strong&gt;GNU/Linux&lt;/strong&gt; for years and I really love the uniqueness and simplicity that some distributions provide. It also provides a close to perfect development environment in my opinion, if you customize it.&lt;br&gt;
But one of the things, probably the most important thing, that I neglected to learn its details was the &lt;strong&gt;Linux kernel&lt;/strong&gt;. I was using various tools for adding a module to the Linux kernel to make a program work (&lt;em&gt;like VirtualBox&lt;/em&gt;) or I was disabling modules to change the purpose of a hardware. But I've never into the Linux kernel really. It was just being updated regularly and sitting there, waiting to be explored.&lt;/p&gt;

&lt;p&gt;My previous experiences taught me that the best way of learning something is &lt;strong&gt;creating a project that solves a problem&lt;/strong&gt; depending on your needs. Also adding some flavors (like using a tech stack that you've not used before) will increase the chance of drowning inside the "&lt;em&gt;ocean of the new stuff&lt;/em&gt;". Which is a good thing because it will force you to swim back to the surface. In the context of the project, it will force you to make the project as perfect as possible and finish it. Because as everyone knows, it's always easier to abandon a project.&lt;/p&gt;

&lt;p&gt;So I've decided to learn the basics of the Linux kernel including kernel types and its history. It was surely a good idea in order to understand the "core" element of the systems we're using today. And then I created my first Linux kernel module that only prints a message when it's loaded and unloaded. It looked like legacy tools like &lt;strong&gt;dmesg&lt;/strong&gt;, &lt;strong&gt;kmod&lt;/strong&gt; and &lt;strong&gt;modprobe&lt;/strong&gt; are preferred most of the time for Linux kernel management on command line. So I've loaded my example kernel module with modprobe and retrieved the log messages with dmesg. Even though I've checked for other alternative tools, I didn't come across a tool that you can do these operations together at the same time.&lt;/p&gt;

&lt;p&gt;Therefore I thought that I should write that tool in a memory-efficient and fast programming language. &lt;strong&gt;Rust!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/fdehau/tui-rs"&gt;tui-rs&lt;/a&gt; is a Rust library for creating &lt;strong&gt;text-based user interfaces&lt;/strong&gt; with different backend options. I've chosen &lt;a href="https://github.com/redox-os/termion"&gt;termion&lt;/a&gt; for the tool that I'm going to write. But still, one thing was missing. I should find a name for it to keep myself motivated while writing it.&lt;/p&gt;

&lt;p&gt;It should be called... Hm... Kernel top? &lt;em&gt;ktop...&lt;/em&gt; Nah, it's taken. How about kernel monitor? &lt;strong&gt;&lt;em&gt;kmon...&lt;/em&gt;&lt;/strong&gt; A-ha! Come on!&lt;/p&gt;

&lt;p&gt;Actually, I've never written something in Rust before kmon. So it was an adventurous journey about the Linux kernel and Rust. I have to say that Rust has a nice development environment and efficient tools like &lt;strong&gt;rustfmt&lt;/strong&gt; and &lt;strong&gt;clippy&lt;/strong&gt;. And writing a Rust application about the Linux kernel on an Arch Linux system... It's not something that you can explain with words.&lt;/p&gt;

&lt;p&gt;Oh what happened at the end of this journey? Well, let me show:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7WiBw6UH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/78243975-68a5f800-74ed-11ea-89b4-d7cfcaeeb6ae.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7WiBw6UH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/78243975-68a5f800-74ed-11ea-89b4-d7cfcaeeb6ae.gif" alt="come on!"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cargo install kmon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;see the information of a module&lt;/li&gt;
&lt;li&gt;search a module&lt;/li&gt;
&lt;li&gt;load/unload a module&lt;/li&gt;
&lt;li&gt;blacklist a module&lt;/li&gt;
&lt;li&gt;and do other cool things&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;in the text-based interface of kmon.&lt;/p&gt;

&lt;p&gt;Here's some examples:&lt;/p&gt;

&lt;h3&gt;
  
  
  Navigating &amp;amp; Scrolling
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Arrow keys&lt;/code&gt; are used for navigating between blocks and scrolling.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KVqRc2jU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/76685750-26447600-6627-11ea-99fd-157449c9529f.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KVqRc2jU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/76685750-26447600-6627-11ea-99fd-157449c9529f.gif" alt="Navigating &amp;amp; Scrolling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Searching a module
&lt;/h3&gt;

&lt;p&gt;Switch to the search area with arrow keys or using one of the &lt;code&gt;/, s, enter&lt;/code&gt; and provide a search query for the module name.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fq3-Hk0P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/76686001-23e31b80-6629-11ea-9e9a-ff92c6a05cdd.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fq3-Hk0P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/76686001-23e31b80-6629-11ea-9e9a-ff92c6a05cdd.gif" alt="Searching a module"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Loading a module
&lt;/h3&gt;

&lt;p&gt;For adding a module to the Linux kernel, switch to load mode with one of the &lt;code&gt;+, i, insert&lt;/code&gt; keys and provide the name of the module to load. Then confirm/cancel the execution of the load command with &lt;code&gt;y/n&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JJa4ved4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/76686027-64429980-6629-11ea-852f-1316ff08ec80.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JJa4ved4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/76686027-64429980-6629-11ea-852f-1316ff08ec80.gif" alt="Loading a module"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The command that used for loading a module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;modprobe &amp;lt;module_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Unloading a module
&lt;/h3&gt;

&lt;p&gt;Use one of the &lt;code&gt;-, u, backspace&lt;/code&gt; keys to remove the selected module from the Linux kernel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d-G-Ri6N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/76686045-8b996680-6629-11ea-9d8c-c0f5b367e269.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d-G-Ri6N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/76686045-8b996680-6629-11ea-9d8c-c0f5b367e269.gif" alt="Unloading a module"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The command that used for removing a module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;modprobe -r &amp;lt;module_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Blacklisting a module
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://wiki.archlinux.org/index.php/Kernel_module#Blacklisting"&gt;Blacklisting&lt;/a&gt; is a mechanism to prevent the kernel module from loading. To blacklist the selected module, use one of the &lt;code&gt;x, b, delete&lt;/code&gt; keys and confirm the execution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yA1fwmsG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/78243543-a5252400-74ec-11ea-932e-4a17c94d74f6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yA1fwmsG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://user-images.githubusercontent.com/24392180/78243543-a5252400-74ec-11ea-932e-4a17c94d74f6.gif" alt="Blacklisting a module"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The command that used for blacklisting a module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if ! grep -q &amp;lt;module_name&amp;gt; /etc/modprobe.d/blacklist.conf; then
  echo 'blacklist &amp;lt;module_name&amp;gt;' &amp;gt;&amp;gt; /etc/modprobe.d/blacklist.conf
  echo 'install &amp;lt;module_name&amp;gt; /bin/false' &amp;gt;&amp;gt; /etc/modprobe.d/blacklist.conf
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ...
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;kmon&lt;/strong&gt; aims to be a standard tool for &lt;strong&gt;Linux kernel management&lt;/strong&gt; while supporting most of the Linux distributions. On that note, here's the distributions that kmon is tested:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Fedora 31&lt;/th&gt;
&lt;th&gt;Debian 10&lt;/th&gt;
&lt;th&gt;Manjaro 19&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cXMqiUze--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/24392180/76520554-27817180-6474-11ea-9966-e564f38c8a6a.png" alt="kmon on fedora"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AWRiBsjX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/24392180/76514129-79bc9580-6468-11ea-9013-e32fbbdc1108.png" alt="kmon on debian"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CYth0jn5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/24392180/76940351-1f5d8200-690b-11ea-8fe9-1d751fe102c5.png" alt="kmon on manjaro"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Ubuntu 18.04&lt;/th&gt;
&lt;th&gt;openSUSE&lt;/th&gt;
&lt;th&gt;Void Linux&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hXD0bYR4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/24392180/76690341-18571b00-6650-11ea-85c9-3f511c054194.png" alt="kmon on ubuntu"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ji_Ab2IL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/24392180/77414512-38b27280-6dd2-11ea-888c-9bf6f7245387.png" alt="kmon on opensuse"&gt;&lt;/td&gt;
&lt;td&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IdLEXzMp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/24392180/77417004-c9d71880-6dd5-11ea-82b2-f6c7df9a05c3.png" alt="kmon on voidlinux"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;More information can be found at the &lt;a href="https://github.com/orhun/kmon"&gt;project page&lt;/a&gt; on GitHub.&lt;/p&gt;

&lt;h3&gt;
  
  
  Links
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/orhun/kmon"&gt;Project Homepage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://crates.io/crates/kmon/"&gt;Rust Package&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.patreon.com/orhunp"&gt;Patreon&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://opencollective.com/kmon"&gt;Open Collective&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Follow &lt;a href="https://twitter.com/kmonitor_"&gt;@kmonitor_&lt;/a&gt; on Twitter&lt;/li&gt;
&lt;li&gt;Follow the &lt;a href="https://orhun.github.io/"&gt;author&lt;/a&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/orhun"&gt;@orhun&lt;/a&gt; on GitHub&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://twitter.com/orhunp_"&gt;@orhunp_&lt;/a&gt; on Twitter&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stay safe.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>rust</category>
      <category>archlinux</category>
      <category>ubuntu</category>
    </item>
  </channel>
</rss>
