(一)编译Linux内核
获取内核源码和源码的解压缩
从www.kernel.org中下载现在最新的linux kernel, 我下载下来的压缩包为: linux-3.10.tar.xz
这个压缩包是有两层包裹的,解压缩:
xz -d linux-3.10.tar.xz
tar -xvf linux-3.10.tar
内核源码的安装
内核源码一般安装在/usr/src/linux \*.\*.\* 目录下,但是我们做编译的时候不要用到系统的这个原内核,而应当
建立我们自己的主目录.
内核文件目录树分析
arch: 特定体系结构源码文件目录
Documentation:内核源码文档
init :内核引导与初始化
lib : 通用内核函数库
sound : 语音系统
block : block层
drivers : 设备驱动程序
ipc : 进程间通信代码目录
tools : 工具目录
COPYING: 内核许可证
Makefile : 内核的基础
usr : 早期用户空间代码
fs : VFS和各种文件系统
mm: 内存管理子系统和VM
scripts: 编译内核所用的脚本
include : 内核头文件
kernel : 核心子系统(如:调度程序)
net : 网络子系统
security : Linux 安全模块
编译内核,配置环境
**编译内核的命令:**
make config : 这个麻烦得要死,会一直询问你yes,no,module(三选一的时候) --- 不推荐
make xconfig : 用于基于X11的图形工具(本文章使用这种方法哈)
make gconfig : 用于基于GTK+图形工具
**make menuconfig : (这种方法使用得比较多) : 用这个之前需要安装相关的包,在这之前需要执行: **
$apt-get install build-essential libncurses5-dev libncurses5
用命令**make xconfig**时遇到的问题:
第一个是:
$ make xconfig
CHECK qt
*
* Unable to find the QT3 installation. Please make sure that
* the QT3 development package is correctly installed and
* either install pkg-config or set the QTDIR environment
* variable to the correct location.
*
make[1]: *** 没有规则可以创建“scripts/kconfig/qconf.o”需要的目标“scripts/kconfig/.tmp_qtcheck”。 停止。
make: *** [xconfig] 错误 2
需要运行如下命令:
#apt-get install libqt3-mt-dev
这个问题解决了之后,我马上遇到了另一个问题:
code::blocks /bin/sh: g++: not found
解决方法: sudo apt-get install g++
问题解决了之后,再次执行
make xconfig 如果成功看到QT界面了,那恭喜了,在这个配置界面中做的修改(一些硬件和驱动信息,有的勾选,没有的就不要了),之后会生成一个.config的文件存放于 你的这个linux内核根目录下
多核编译
默认情况下make(1)只衍生一个作业,为了让多个作业一起编译内核,可以使用下面的命令
sudo make -jn (n表示你要的作业数)
这一过程大约需要40-100分钟,具体的要看你的机器速度啦……
编译模块
sudo make modules
安装模块(没有执行此命令的话,你的驱动将不会被挂载哦~~)
sudo make modules\_install
安装内核
内核编译好了之后,就要进行安装了.
sudo make install
安装完毕之后
root@FE2000:/usr/src/linux# cd /
root@FE2000:/usr/src/linux# /usr/sbin/mkinitramfs -o /boot/initrd.img-3.10(这个大家的不一样哈)
如果有出错提示,可能是因为 initramfs-tools 没有装,先把它装上吧。
如果没有这一步骤,那么开机就会出现提示
……
initrd /initrd.img-3.10
Error 15: File not found
修改内核启动选项(更新grub)
$sudo update-grub
这条命令执行完之后会自动将刚才编译好的内核放在启动菜单项的第一个,如果想要自己修改启动菜单项中的启动顺序,则修改
/boot/grub/grub.cfg 文件中的 set default = (这里写值)
还没有评论,来说两句吧...