ubuntu kernel 2.6 kernel-module make
ubuntu linux-source packageComments
からのつづき
2.6のモジュールmake数年ぶりに
やってみた。
見事に忘れてたよう
http://d.hatena.ne.jp/toshi_hirasawa/20120206/1328530240
http://d.hatena.ne.jp/toshi_hirasawa/comment?date=20090301§ion=1235900337
資料を探すには module_param にてググると所望のものがみつかりやすい。
たとえばここがよさげ
http://www.hakodate-ct.ac.jp/~tokai/tokai/research/kmod.html
Centos 6.3のソースコードの入手は
http://kanjuku-tomato.blogspot.jp/2013/03/centos-63.html
がいいかとおもいます。
[hirasawa@ubunt1004-32-2 ~]$ uname -a Linux ubunt1004-32-2 2.6.32-38-generic #83-Ubuntu SMP Wed Jan 4 11:13:04 UTC 2012 i686 GNU/Linux [hirasawa@ubunt1004-32-2 ~]$ [hirasawa@ubunt1004-32-2 ~]$ lsmod | grep hello [hirasawa@ubunt1004-32-2 ~]$ ls -ltr |grep hello-ko -rw-r--r-- 1 hirasawa hirasawa 441 2012-02-11 16:33 hello-ko.c [hirasawa@ubunt1004-32-2 ~]$ cat hello-ko.c #include <linux/module.h> // required by all modules #include <linux/kernel.h> // required by printk() #include <linux/init.h> MODULE_LICENSE("GPL"); MODULE_AUTHOR("toshi"); // Start/Init function static int hello_init(void) { printk(KERN_ALERT "Hello world!\n"); return 0; } // End/Cleanup function static void hello_exit(void) { printk(KERN_ALERT "Goodbye world!\n"); } module_init(hello_init); module_exit(hello_exit); [hirasawa@ubunt1004-32-2 ~]$ cat Makefile obj-m := hello-ko.o KDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules [hirasawa@ubunt1004-32-2 ~]$ make make -C /lib/modules/2.6.32-38-generic/build SUBDIRS=/home/hirasawa modules make[1]: ディレクトリ `/usr/src/linux-headers-2.6.32-38-generic' に入ります CC [M] /home/hirasawa/hello-ko.o Building modules, stage 2. MODPOST 1 modules CC /home/hirasawa/hello-ko.mod.o LD [M] /home/hirasawa/hello-ko.ko make[1]: ディレクトリ `/usr/src/linux-headers-2.6.32-38-generic' から出ます [hirasawa@ubunt1004-32-2 ~]$ ls -ltr |grep hello-ko -rw-r--r-- 1 hirasawa hirasawa 441 2012-02-11 16:33 hello-ko.c -rw-r--r-- 1 hirasawa hirasawa 1360 2012-02-11 18:56 hello-ko.o -rw-r--r-- 1 hirasawa hirasawa 690 2012-02-11 18:56 hello-ko.mod.c -rw-r--r-- 1 hirasawa hirasawa 1856 2012-02-11 18:56 hello-ko.mod.o -rw-r--r-- 1 hirasawa hirasawa 2614 2012-02-11 18:56 hello-ko.ko [hirasawa@ubunt1004-32-2 ~]$ sudo insmod hello-ko.ko [hirasawa@ubunt1004-32-2 ~]$ lsmod |grep hello hello_ko 680 0 [hirasawa@ubunt1004-32-2 ~]$ tail -1 /var/log/kern.log Feb 11 18:56:57 ubunt1004-32-2 kernel: [25787.868153] Hello world! [hirasawa@ubunt1004-32-2 ~]$ sudo rmmod hello-ko.ko [hirasawa@ubunt1004-32-2 ~]$ tail -1 /var/log/kern.log Feb 11 18:58:07 ubunt1004-32-2 kernel: [25857.748515] Goodbye world! [hirasawa@ubunt1004-32-2 ~]$