日期:2014-05-16 浏览次数:20719 次
yum -y install kernel-devel kernel-headers
Installed: kernel-devel.i686 0:2.6.35.10-74.fc14 Updated: kernel-headers.i686 0:2.6.35.10-74.fc14
uname -a
Linux fedora14 2.6.35.6-45.fc14.i686 #1 SMP Mon Oct 18 23:56:17 UTC 2010 i686 i686 i386 GNU/Linux
#include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ #include <linux/init.h> /* Needed for the macros */ static int __init hello_start(void) { printk(KERN_INFO "Loading hello module...\n"); printk(KERN_INFO "Hello world\n"); return 0; } static void __exit hello_end(void) { printk(KERN_INFO "Goodbye Mr.\n"); } module_init(hello_start); module_exit(hello_end);
# Comment/uncomment the following line to disable/enable debugging #DEBUG = y # Add your debugging flag (or not) to CFLAGS ifeq ($(DEBUG),y) DEBFLAGS = -O -g # "-O" is needed to expand inlines else DEBFLAGS = -O2 endif EXTRA_CFLAGS += $(DEBFLAGS) #-I$(LDDINCDIR) ifneq ($(KERNELRELEASE),) # call from kernel build system obj-m := helloworld.o else KERNELDIR ?= /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules #LDDINCDIR=$(PWD)/../include modules endif clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions depend .depend dep: $(CC) $(CFLAGS) -M *.c > .depend ifeq (.depend,$(wildcard .depend)) include .depend endif
make
make -C /lib/modules/2.6.35.6-45.fc14.i686/build M=/home/liweinan/projs modules #LDDINCDIR=/home/liweinan/projs/../include modules make[1]: Entering directory `/usr/src/kernels/2.6.35.6-45.fc14.i686' CC [M] /home/liweinan/projs/helloworld.o Building modules, stage 2. MODPOST 1 modules CC /home/liweinan/projs/helloworld.mod.o LD [M] /home/liweinan/projs/helloworld.ko make[1]: Leaving directory `/usr/src/kernels/2.6.35.6-45.fc14.i686'
insmod helloworld.ko
dmesg | tail
[ 1138.690913] helloworld: module license 'unspecified' taints kernel. [ 1138.690915] Disabling lock debugging due to kernel taint [ 1138.691012] Loading hello module... [ 1138.691014] Hello world
-1 Invalid module format