Skip to content

Commit

Permalink
feat: insmod/rmmod, updating README and renaming get_load_command()
Browse files Browse the repository at this point in the history
  • Loading branch information
tpiekarski committed Jun 10, 2020
1 parent 640eb9b commit 5354f2c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 40,7 @@ There are different kernel designs due to the different ways of managing system
Although the Linux-based operating systems dominate the most of computing, it still carries some of the design flaws which were quite a bit of debate in the early days of Linux. For example, it has the **largest footprint** and **the most complexity** over the other types of kernels. But it's a design feature that monolithic kernels inherent to have. These kind of design issues led developers to add new features and mechanisms to the Linux kernel which other kernels don't have.

Unlike the standard monolithic kernels, the Linux kernel is also **modular**, accepting **loadable kernel modules (LKM)** that typically used to add support for new *hardware* (as device drivers) and/or *filesystems*, or for adding *system calls*. Since LKMs could be loaded and unloaded to the system *at runtime*, they have the advantage of extending the kernel without rebooting and re-compiling. Thus, the kernel functionalities provided by modules would not reside in memory without being used and the related module can be unloaded in order to free memory and other resources.
Loadable kernel modules are located in `/lib/modules` with the `.ko` (*kernel object*) extension in Linux. While the [lsmod](https://linux.die.net/man/8/lsmod) command could be used for listing the loaded kernel modules, [modprobe](https://linux.die.net/man/8/modprobe) is used for loading or unloading a kernel module.
Loadable kernel modules are located in `/lib/modules` with the `.ko` (*kernel object*) extension in Linux. While the [lsmod](https://linux.die.net/man/8/lsmod) command could be used for listing the loaded kernel modules, [modprobe](https://linux.die.net/man/8/modprobe) or [insmod](https://linux.die.net/man/8/insmod)/[rmmod](https://linux.die.net/man/8/rmmod) is used for loading or unloading a kernel module. insmod/rmmod are used for modules independent of modprobe and without requiring an installation to ```/lib/modules/$(uname -r)```.

Here's a simple example of a Linux kernel module that prints a message when it's loaded and unloaded. The build and installation steps of the [module](https://github.com/orhun/kmon/blob/master/example/lkm_example.c) using a [Makefile](https://github.com/orhun/kmon/blob/master/example/Makefile) are shown below.

Expand Down Expand Up @@ -331,7 331,7 @@ For adding a module to the Linux kernel, switch to load mode with one of the ` ,
The command that used for loading a module:

```
modprobe <module_name>
modprobe <module_name> || insmod <module_name>.ko
```

### Unloading a module
Expand All @@ -343,7 343,7 @@ Use one of the `-, u, backspace` keys to remove the selected module from the Lin
The command that used for removing a module:

```
modprobe -r <module_name>
modprobe -r <module_name> || rmmod <module_name>
```

### Blacklisting a module
Expand All @@ -370,7 370,7 @@ Use `ctrl-r` or `alt-r` key for reloading the selected module.
The command that used for reloading a module:

```
modprobe -r <module_name> && modprobe <module_name>
modprobe -r <module_name> || rmmod <module_name> && modprobe <module_name> || insmod <module_name>.ko
```

### Clearing the ring buffer
Expand Down
6 changes: 3 additions & 3 deletions src/kernel/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 64,7 @@ impl ModuleCommand {
match self {
Self::None => Command::new(String::from(""), "", format!("Module: {}", module_name), Symbol::None),
Self::Load => Command::new(
Self::get_load_command(&module_name),
Self::get_load_commandline(&module_name),
"Add and remove modules from the Linux Kernel\n
This command inserts a module to the kernel.",
format!("Load: {}", module_name), Symbol::Anchor),
Expand Down Expand Up @@ -134,11 134,11 @@ impl ModuleCommand {
}

/**
* Get load command based upon module_name
* Get load command line based upon module_name
*
* @return String
*/
pub fn get_load_command(module_name: &str) -> String {
pub fn get_load_commandline(module_name: &str) -> String {
if !Self::is_module_filename(&module_name) {
format!("modprobe {0} || insmod {0}.ko", &module_name)
} else {
Expand Down

0 comments on commit 5354f2c

Please sign in to comment.