目的:通过实践学习内核源码

 

准备工作

1. 编译环境搭建

ubuntu中只需要一条命令就可以安装所有源代码编译工具:

# apt-get install build-essential

sudo root

ubuntu安装时没有提示设置root密码,默认不启动root用户。可使用sudo passwd root 输入安装时的密码设置root密码。

apt-get update

 

2. 源码获取

方法1:http://www.kernel.org/获取

wget http://www.kernel.org/...

方法2:获取当前版本内核源码

root@whocare-MS-7551:/home/whocare# apt-cache search linux-source
linux-source - Linux kernel source with Ubuntu patches
linux-source-3.0.0 - Linux kernel source for version 3.0.0 with Ubuntu patches
root@whocare-MS-7551:/home/whocare# apt-get install linux-source-3.0.0

方法3:获取最新版本源代码

cd /data/kernel-core2
git clone git://kernel.ubuntu.com/ubuntu/ubuntu-maverick.git source

本文采用方法2。

3. 解压源码

root@whocare-MS-7551:/usr/src/linux-source-3.0.0# tar -xjvf linux-source-3.0.0.tar.bz2
 

编译

1. 清空编译配置

root@whocare-MS-7551:/usr/src/linux-source-3.0.0/linux-source-3.0.0# make mrproper
  CLEAN   scripts/basic
  CLEAN   include/config
 

2. 编译选项配置

root@whocare-MS-7551:/usr/src/linux-source-3.0.0/linux-source-3.0.0# make menuconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
 *** Unable to find the ncurses libraries or the
 *** required header files.
 *** 'make menuconfig' requires the ncurses libraries.
 ***
 *** Install ncurses (ncurses-devel) and try again.
 ***
make[1]: *** [scripts/kconfig/dochecklxdialog] 错误 1
make: *** [menuconfig] 错误 2
 

提示缺少ncurses

Ncurses是一个字符终端处理库,包括面板和菜单。

安装Ncurses

root@whocare-MS-7551:/usr/src/linux-source-3.0.0/linux-source-3.0.0# apt-get install libncurses5-dev

再make menuconfig

修改General setup --->
()  Local version - append to kernel release ()

保存

启动编译

make all

make install

make modules_install

 

验证编译结果

重启电脑,进入内核选择界面时,选择编译的内核进入。