A simple template to get started with writing a C LKM. Supports hot-reloading and a qemu VM.
The default paths for scripts in this template are:
KERNEL:../linuxBUSYBOX:../busybox
So, you should have a KERNEL dir with a rust enabled kernel already built and
a BUSYBOX dir with a ALREADY built and configured busybox.
For automating the setup of the environment, run the setup script:
./scripts/setupRefer to the script for more info.
I wrote a simple wrapper script for the make command for compiling this LKM.
It is located in the scripts directory. You can use it like this:
./scripts/build
./scripts/build -t help
./scripts/build -t clean
./scripts/build -k /path/to/linux -b /path/to/busybox
# ... and so onPlease refer to the kernel docs for more info on basic Kbuild usage.
First, build the LKM. Then, you can use the run script to run it in a qemu VM:
# Default locations: KERNEL=../linux, BUSYBOX=../busybox
./scripts/run
# Custom locations
./scripts/run -k /path/to/linux -b /path/to/busyboxThis script will simply copy all the .ko files to the initramfs and run the
VM.
You can use the hot-reload script to hot-reload the LKM in the running VM:
./scripts/hot-reloadIt uses the entr utility to watch for changes in the source code and then
running ./scripts/build to build the LKM and ./scripts/run to run it in the
VM. Please refer to the script for more info.