本次采用的版本是CentOS 5.5,其原始的内核版本是2.6.18-194.el5 要升级到的版本是2.6.39.4
本次实验采用的内核是从官方下载的2系列的最后一个版本
[root@localhost ~]# yum install ncurses-devel ncurses(安装为接下来的make menuconfig提供面板所需要的套件)
[root@localhost ~]# cd /usr/src/kernels/
[root@localhost kernels]# ll linux-2.6.39.4.tar.bz2 (新内核的源码包)
-rw-r--r-- 1 root root 76097195 Oct 22 2011 linux-2.6.39.4.tar.bz2
[root@localhost kernels]# tar jxvf linux-2.6.39.4.tar.bz2
[root@localhost linux-2.6.39.4]# make mrproper (清除旧目标文件和配置)
[root@localhost linux-2.6.39.4]#make menuconfig(根据自己系统的需要,配置内核选项)
[root@localhost linux-2.6.39.4]# vi .config (找到带注释的那行,加上以下的那句话,注意版本)
# CONFIG_SCHED_AUTOGROUP is not set
CONFIG_SYSFS_DEPRECATED=y
做上步红色字体这个设置是为了应对reboot时出现的以下问题
mount:could not find filesystem '/dev/root'
setuproot:moving /dev failed :No such file or directory
setuproot:error mounting /proc:No such file or directory
setuproot:error mounting /sys:No such file or directory
switchroot:mount failed:No such file or directory
Kernel panic - not syncing:Attempted to kill init!
pid:1.comm:init Not tainted 2.6.39.4 #1
[root@localhost linux-2.6.39.4]# make(编译内核)
[root@localhost linux-2.6.39.4]# make modules(编译内核模块)
[root@localhost linux-2.6.39.4]# make modules_install(安装内核模块)
[root@localhost linux-2.6.39.4]# make install(安装新内核)
以下蓝色字体的设置是为了应对reboot时出现的下列两个问题
insmod: error inserting '/lib/dm-region-hash.ko' : -1 File exists
insmod: error inserting ‘/lib/dm-mirror.ko’: -1 Unknow symbol in module
然后修改initrd-2.6.39.4.img (此部分内容是拾人牙慧,故不做本质的修改)
[root@localhost ~]# mdkir -p /tmp/newinitrd
[root@localhost tmp]# cp /boot/initrd-2.6.39.4.img .
[root@localhost tmp]# cd newinitrd/
[root@localhost newinitrd]# zcat ../initrd-2.6.39.4.img |cpio -i
[root@localhost newinitrd]# vi init(删掉其中重复的四行中的两行,同时删去带关键字“mirror”的两行)
echo "Loading dm-region-hash.ko module"
insmod /lib/dm-region-hash.ko
echo "Loading dm-region-hash.ko module"
insmod /lib/dm-region-hash.ko
[root@vhost newinitrd]# find .|cpio -c -o > ../initrd(重新打包initrd)
11282 blocks
[root@vhost newinitrd]# cd ..
[root@vhost tmp]# gzip -9 < initrd > initrd.img
[root@localhost tmp]# ll initrd.img (此时的initrd.img是全新的)
-rw------- 1 root root 3366619 Oct 16 00:44 initrd.img
接着就是覆盖boot下的initrd
[root@localhost tmp]# mv /boot/initrd-2.6.39.4.img /boot/initrd-2.6.39.4.img.bak(做备份,防患于未然)
[root@localhost tmp]# cp initrd.img /boot/initrd-2.6.39.4.img
最后就是修改启动设置
[root@localhost ~]# vi /boot/grub/menu.lst (把默认启动设置成新内核)
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.39.4)
root (hd0,0)
kernel /vmlinuz-2.6.39.4 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.39.4.img
title CentOS (2.6.18-194.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.18-194.el5.img
最后
[root@localhost ~]# reboot(无错误提示重启成功,查看新的内核版本,会发现改变)
总结:
已经接触了Linux很久了,在对系统有一定了解之后,今天决定第一次尝试编译linux内核,毕竟内核编译是网管员必修的功课,当然中间也出现了一些小问题,通过谷歌问题顺利的解决,升级内核成功!