This project implements a simple Linux kernel module (KMM) named kmt, which demonstrates the use of sysfs attributes for interacting with kernel modules. The module provides several attributes that can be read from and written to via the sysfs filesystem, allowing users to interact with the kernel module directly.
-
Sysfs Attributes: The module exposes four attributes:
status: Indicates the current status of the module (active/inactive).message: A customizable message that can be set by the user.version: Displays the version of the module.mode: Allows setting and retrieving the operational mode of the module.
-
Dynamic Message Handling: Users can dynamically change the message displayed by the module through the sysfs interface.
-
Easy Integration: The module can be built and integrated easily into a Linux kernel environment.
- Linux kernel headers matching your running kernel version.
- Build tools such as
makeandgcc.
-
Clone the repository:
git clone https://github.com/yourusername/kernel-module-sysfs.git cd kernel-module-sysfs -
Build the module:
make
-
Load the module:
sudo insmod kmt.ko
-
Verify the module is loaded:
dmesg | tail -n 10 -
Interact with sysfs attributes:
- Check the status:
cat /sys/class/driver/hello_world_driver/status
- Set a message:
echo "Hello, World!" > /sys/class/driver/hello_world_driver/message
- Check the message:
cat /sys/class/driver/hello_world_driver/message
- Check the version:
cat /sys/class/driver/hello_world_driver/version
- Set the mode:
echo "custom_mode" > /sys/class/driver/hello_world_driver/mode
- Check the mode:
cat /sys/class/driver/hello_world_driver/mode
- Check the status:
-
Remove the module:
sudo rmmod kmt
To remove the compiled module and associated files, run:
make cleanThis kernel module can be used for educational purposes to demonstrate the interaction between user space and kernel space through sysfs. It can also be extended to include more complex behaviors and additional attributes.
This project is licensed under the GNU General Public License v2.0 - see the LICENSE file for details.