0%

编译linux内核

要在centos上安装一个文件,内核不支持,不得已编译一下内核:

cd /usr/src
wget http://www.kernel.org/pub/linux/kernel/v3.0/testing/linux-3.1-rc2.tar.bz2
tar jxvf linux-3.1-rc2.tar.bz2
cd linux-3.1-rc2
make menuconfig # 需要ncurse apt-get install ncurses-dev
make defconfig oldconfig xconfig

 

 


1、准备工作

我安装的是ubuntu10.04,为完成内核编译,还需要安装一下包:

apt-get install gcc

apt-get install make

apt-get install bzip2

apt-get install libc6-dev

apt-get install ncurse-dev

apt-get install initrd-tools ####为了使用mkinitrd命令生成initrd.img-XXX

其中在安装initrd-tools时,可能出现找不到安装包的情况,这是因为新版本的ubuntu或debian已经用新的软件取代了
该软件,此时要保证含有命令mkinitramfs,mkinitramfs-kpkg
apt-get install kernel-package
2、下载源码

可以在官网www.kernel.org下载响应的源码(下载完整版F),也可以wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.tar.bz2命令获取。
#wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.tar.bz2

#tar xjf linux-2.6.39.tar.bz2 -C /usr/src
3、配置文件

根据自己机器的硬件情况,选择内核编译配置选项,在这里我使用的是默认配置(make menuconfig后直接保存退出,生成.config文件);具体配置可以参考金步国先生翻译的资料:Linux 2.6.19.x 内核编译配置选项,参考网址:http://lamp.linux.gov.cn/Linux/kernel_options.html

#cd /usr/src/linux-2.6.39

#make menuconfig

 

4、编译内核

#make clean ####第一次编译可以省略

#make mrproper ####第一次编译可以省略

#make

 

5、编译和安装模块

#make modules

make modules_install

 

6、生成内核镜像文件
#makinitramfs -o /boot/initrd-2.6.39.img /lib/modules/2.6.39 ##启动、加载模块

cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.39 ##可引导的、压缩的内核

cp System.map /boot/System.map-2.6.39 ##kernel 索引

cp .config /boot/config-2.6.39 #内核配置文件

7、设置启动项
启动项是/boot/grub/grub.cfg文件,我们需要修改该文件,具体如下:

首先,复制下面内容。
menuentry ‘Ubuntu, with Linux 2.6.32-32-generic’ –class ubuntu –class gnu-linux –class gnu –class os {
recordfail
insmod ext2
set root=’(hd0,4)’
search –no-floppy –fs-uuid –set 8450af8f-090b-4eae-a123-6f1e3604fa9e
linux /boot/vmlinuz-2.6.32-32-generic root=UUID=8450af8f-090b-4eae-a123-6f1e3604fa9e ro quiet splash
initrd /boot/initrd.img-2.6.32-32-generic
}

然后,对上面内容进行响应的修改,红色部分。
menuentry ‘Ubuntu_Test, with Linux 2.6.39’ –class ubuntu –class gnu-linux –class gnu –class os {
recordfail
insmod ext2
set root=’(hd0,4)’
search –no-floppy –fs-uuid –set 8450af8f-090b-4eae-a123-6f1e3604fa9e
linux /boot/vmlinuz-2.6.39 root=UUID=8450af8f-090b-4eae-a123-6f1e3604fa9e ro quiet splash
initrd /boot/initrd.img-2.6.39
}
grub-mkconfig update-grub

8、测试
重启,选择Ubuntu_Test, with Linux 2.6.39进入ubuntu系统,最后通过命令uname -a查看系统的内核信息。

结果还是不行,看了这玩意儿真不是一般人玩得的。只能升级linux系统。