单独编译Linux内核中的某一模块
时间:2010-11-02 来源:chenjie625
当然可以!方法如下:
1.首先将jbd的代码(在Linux源码/fs/jbd目录)整个拷贝出来; 2.将jbd代码中的Makefile进行修改: 原Makefile的内容如下:
# # Makefile for the linux journaling routines. # obj-$(CONFIG_JBD) += jbd.o jbd-objs := transaction.o commit.o recovery.o checkpoint.o revoke.o journal.o |
修改后的Makefile如下:
# Makefile for jbd TARGET = jbd OBJECT = transaction.o commit.o recovery.o checkpoint.o revoke.o journal.o
ifneq ($(KERNELRELEASE),) #kbuild syntax. obj-m += $(TARGET).o $(TARGET)-objs := $(OBJECT) else PWD := $(shell pwd) KERNEL_DIR := /lib/modules/`uname -r`/build
all : modules
modules: $(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules install: install ./$(TARGET).ko /usr/local/lib /sbin/insmod ./$(TARGET).ko
uninstall: rm -f /usr/local/lib/$(TARGET).ko /sbin/rmmod $(TARGET).ko
insmod: /sbin/insmod ./$(TARGET).ko
rmmod: /sbin/rmmod $(TARGET).ko
clean: rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions Module.markers modules.order Module.symvers endif |
3.编译模块: $ make
4.加载模块: $sudo make insmod
5.卸载模块: $sudo make rmmod