Home Linux Kernel Manage And Monitor Linux Kernel Modules With Kmon

Manage And Monitor Linux Kernel Modules With Kmon

By sk
Published: Last Updated on 1.8K views

Kmon is a an open source Linux Kernel manager and activity monitor utility written in Rust programming language. It is a simple text-user interface (TUI) tool for managing Linux kernel modules and monitoring Kernel activities. It allows the users to load, unload, blacklist and display the information of a Kernel module. All of these kernel management activities,  hardware logs and other Kernel messages are tracked and showed by the real-time activity monitor in Kmod. In this brief guide, we will learn how to manage and monitor Linux kernel modules with Kmon.

Install Kmon in Linux

Since it is written in Rust, Kmon can be installed using Cargo package manager. Install Rust on your Linux box as described in the following link.

And then run the following command to install Kmon:

$ cargo install kmon

Kmon is available in AUR. So you can install it using any AUR helper tools, for example Yay, like below.

$ yay -S kmon

Kmon is also available in Copr repository. On Fedora and other RPM-based systems, enable Kmon repository and install it as shown below.

$ sudo dnf copr enable atim/kmon
$ sudo dnf install kmon

On other Linux distributions, download the latest Kmon binaries from releases page.

As of writing this guide, the latest version was 1.0.1.

$ wget https://github.com/orhun/kmon/releases/download/v1.0.1/kmon-1.0.1.tar.gz

Extract the downloaded archive:

$ tar -xvzf kmon-1.0.1.tar.gz

Move/copy the Kmon binary to your $PATH.

$ sudo cp kmon /usr/local/bin/

Move/copy the Kmon man page file to /usr/local/man/man8/ directory.

$ sudo mkdir /usr/local/man/man8/
$ sudo gzip /usr/local/man/man8/kmon.8

Additionally, you should install the libxcb package to copy/paste commands in headless servers.

On Debian/Ubuntu:

$ sudo apt install libxcb1-dev

On Fedora/CentOS:

$ sudo dnf install libxcb-devel

Manage And Monitor Linux Kernel Modules With Kmon

To launch Kmon, simply run the following command from the Terminal:

$ kmon
Manage And Monitor Linux Kernel Modules With Kmon

Manage And Monitor Linux Kernel Modules With Kmon

As you can see in the above output, Kmon has 5 blocks.

  • Search box on the top left - Allows the users to search for a specific Kernel module.
  • Kernel Release on the top middle - Display the currently loaded Kernel release number. Keep hitting TAB key to display Kernel version and Kernel platform.
  • Loaded Kernel Modules below Search- box - Display the list of loaded modules.
  • Module on the top right - Shows the information of selected module from the Loaded Kernel Modules block.
  • Kernel Activities in the bottom - Displays all Kernel activities, hardware logs and other Kernel messages.

Display Kmon help

Press the ? or F1 key to display help section.

Display Kernel details

To view the currently loaded Kernel version, release number and platform, press TAB key.

Switch between blocks

You can switch between blocks using right/left arrows or h/l keys.

Scroll UP/DOWN inside blocks

Use up/down, k/j, alt-k/j keys to scroll up or down inside a selected block.

Scroll UP/DOWN Kernel activities

Press PgUp/PgDn keys to scroll up and down the Kernal activities. Similarly, to scroll left or right (horizontally) Kernel activities, press  alt-h and alt-l keys. This can be useful when reading a lengthy Kernel activity message that doesn't fit into the Kernel Activities block.

Smooth scrolling

Use alt-j and alt-k keys to scroll kernel activity and module information blocks slowly.

Display Kernel Module Details

To view the information of a specific Kernel module, just select it using UP/DOWN arrows in the Loaded Kernel Modules block. The selected module will be displayed in Module block.

Search a Kernel module

Select the Search box using arrow keys or press s or / or ENTER keys and type the name of the module in the search box.

Search kernel module in Kmon

Search kernel module in Kmon

Load modules

To load a module to your Linux Kernel, press one of the + or i or insert keys to switch to load mode. You can also press UP/DOWN arrows to switch between Search mode and Load mode. Type the name of the module that you want to load.

Type Kernel module name in Load mode in Kmon

Load modules

Finally, press Y to confirm loading module. To cancel the loading operation, simply press n.

Load modules to Linux kernel with Kmon

Load modules to Linux kernel with Kmon

The command used to load the module will be shown in the right side.

$ modprobe <module_name>

Unload modules

Select a module that you want to unload from the Linux kernel in the Loaded Kernel Modules block. And then press - or u or backspace keys and press Y to remove the selected module from the Linux kernel.

Unload modules from Linux kernel with Kmon

Unload modules from Linux kernel with Kmon

The command used to load the module will be shown in the right side.

$ modprobe -r <module_name>

Blacklist modules

Kmon allows us to blacklist a module i.e prevent from being loaded in Linux Kernel. Select the module that you want to blacklist from Loaded Kernel Modules block and press x or b or delete keys and press Y to confirm the operation.

Blacklist kernel modules with Kmon

Blacklist kernel modules with Kmon

The command used to blacklist the selected module will be shown in the right side.

if ! grep -q <module_name> /etc/modprobe.d/blacklist.conf; then
  echo 'blacklist <module_name>' >> /etc/modprobe.d/blacklist.conf
  echo 'install <module_name> /bin/false' >> /etc/modprobe.d/blacklist.conf
fi

Copy/paste

To copy contents from Kmon interface to your Terminal or in a text file, use c and v keys. Make sure you have installed libxcb package as shown in the installation section.

Sort Kernel modules

Kmon has an option to sort Kernel modules by name or size.

To sort Kernel modules by name, run kmon command with sort option like below.

$ kmon sort --name

To sort Kernel modules by size, run:

$ kmon sort --size

We can also do reverse sorting Kernel modules using r or reverse flags.

$ kmon --reverse

Customize color

Kmon uses your Terminal colors by default. However, it is possible to change the highlighting colors.

$ kmon --color majenta

Or,

$ kmon -c majenta

You can even specify a custom color of your choice with color code like below.

$ kmon --color 00aeef
Customize Kmon highlighting color

Customize Kmon highlighting color

Set refresh interval

To set Terminal UI refresh interval in milliseconds, use -t or --tickrate flag:

$ kmon --color 00aeef -t 100

Clear Kernel ring buffer

We can clear the Kernel ring buffer with the ctrl-l/u or alt-c keys.

Exit Kmon

To quit Kmon, simply press q or ESC key.

For more details, refer help section:

$ kmon --help

And also man pages:

$ man kmon

Hope this helps.

Resource:

Related read:

You May Also Like

3 comments

Jalal April 8, 2020 - 10:10 am

Hi,
Very useful article
thanks a lot
note:
in Line
Kernel Activities in the bottom – Displays all Kernel activities, hardware logs and other Kerne messages.
missing ‘L’ from kerne messages

Reply
sk April 8, 2020 - 11:01 am

Good catch. Fixed it. Thank you.

Reply
Saran May 12, 2021 - 3:19 pm

Never heard about this application. Thanks for bringing it to my attention.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More