Basic module - Hello world
cd 01-hello && make && sudo insmod hello.ko
dmesg | tail
sudo rmmod helloCharacter device - Read/write device
cd 02-chardev && make && sudo insmod simple_char.ko
echo "test" > /dev/simple_char
cat /dev/simple_char
sudo rmmod simple_charAll examples support:
make- Build modulemake clean- Remove build filessudo insmod module.ko- Load modulesudo rmmod module- Unload moduledmesg | tail- View kernel log
- Edit code
- Build:
make - Load:
sudo insmod module.ko - Test: Run tests
- Check logs:
dmesg | tail - Unload:
sudo rmmod module - Repeat
# Watch kernel log in real-time
dmesg -w
# Check module is loaded
lsmod | grep module_name
# Verbose module info
modinfo module.ko
# Check for errors
dmesg | grep -i error
# Enable dynamic debug
echo 'file simple_char.c +p' > /sys/kernel/debug/dynamic_debug/controlEach example contains:
*.c- Source code with detailed commentsMakefile- Build configurationREADME.md- Specific usage instructions
All examples are self-contained and can be built independently.