1,搜索源码包
apt-get update
搜索源码包
root@demo-2:~/dm# apt-cache search linux-source
linux-source-3.2 - Linux kernel source for version 3.2 with Debian patches
linux-source - Linux kernel source (meta-package)
linux-source-2.6 - Linux kernel source (dummy package)
linux-source-3.16 - Linux kernel source for version 3.16 with Debian patches
2、构造源码树
tar -xvjf linux-source-2.6.26.tar.bz2
apt-get install ncurses-dev
# make
# make bzImage
# make modules // 编译模块
# make modules_install // 安装模块
OK 完成!
在/lib/modules下生成新的目录/lib/modules/2.6.26-2-generic/。 在编译驱动模块时,要用到这个路径下的build目录。
前在Ubuntu里写个kernel module 的 hello world. make出错.后来知道是因为Ubuntu没有KERNEL 原码树, 以为Ubuntu主打桌面,而且Ubuntu桌面是比较慢.
所以就换用Debian了. 但是Debian 装好后还是没有原码树…
所以在这里记录一下安装的方法:
1. 查看自己系统的内核版本:
hengl@lhdebian:~$ uname -r
2.6.26-1-686
2. 安装相应版本的内核原码包:
hengl@lhdebian:~$ sudo apt-get install linux-source-2.6.26
然后在/usr/src/ 下就会有内核原码包,是一个压缩包.
hengl@lhdebian:~$ ls /usr/src/
linux-source-2.6.26.tar.bz2
3. 解压该包:
hengl@lhdebian:/usr/src$ sudo tar -xvf linux-source-2.6.26
然后会生成内核原码目录: linux-source-2.6.26
4. 配置内核:
hengl@lhdebian:/usr/src/linux-source-2.6.26$ sudo make oldconfig
也可以使用别的配置方式 : menuconfig , xconfig. 看自己的需求了.
5. 编译内核:
hengl@lhdebian:/usr/src/linux-source-2.6.26$ sudo make bzImage
这个操作要花一些时间,然后会在当前目录下www.linuxidc.com生成一个新的文件: vmlinux
6. 编译 模块:
hengl@lhdebian:/usr/src/linux-source-2.6.26$ sudo make modules
这里要花更长一些时间… …
7.安装 模块:
hengl@lhdebian:/usr/src/linux-source-2.6.26$ sudo make modules_install
然后会在 /lib/modules/ 目录下生成 目录 : 2.6.26. make 模块的时候用到的就是它了.
至此, 就搞了, 重启一下系统, 写个网上到处可以找到的hello world试试:
//hello.c
#include
#include
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(