To show the current kernel version:
uname -r
The installed kernel modules are located int the /lib/modules//build directory.
modinfo [-k <kernel version>] <module> # info about installed module
insmod <mod name>.ko # load a module into the kernel
rmmod <mod name>.ko # removed a module from the kernel
modprobe <mod name> # load an installed module
lsmod # list all the loaded modules
The kernel levels are the following:
ID | Level |
---|---|
0 | Emergency |
1 | Alert |
2 | Critical |
3 | Error |
4 | Warning |
5 | Notice |
6 | Informations |
7 | Debug |
dmesg is used to show all kernel messages:
dmesg
dmesg -n <log level> # turn off all levels under it
echo "N" > /proc/sys/kernel/printk # same as the command before
To emulate printk logging level, echo can be used:
echo "<N> Message" > /dev/msg # show messages under N logging level
A great guide can be found here.
The coding style can be found here.
The kernel modules Makefile can be setup for cross compiling as following.
obj-m += hello.o
SYSROOT :=
KDIR := $(SYSROOT)/usr/src/kernel
ARCH := x86
CROSS_COMPILE := i586-poky-linux-
all: build
build:
make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
A kernel module signing guide can be found here.
Before signing kernel modules, the /usr/src/kernel directory must be configured with the following command:
sudo make -C /usr/src/kernel scripts
Then it's possible to use a Makefile rule for automatic sign, just in case the kernel module must be loaded manually for tests:
sign:
env LANG=C perl $(KDIR)/scripts/sign-file sha1 \
$(KDIR)/signing_key.priv \
$(KDIR)/signing_key.x509 \
hello.ko
env LANG=C
is used to avoid perl warnings.