一、下载内核文件并解压至相应目录
# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.4.tar.bz2
# tar jxvf linux-2.6.39.4.tar.bz2
# mv linux-2.6.39.4 /usr/src
二、简要的配置内核
# cd /usr/src/linux-2.6.39.4
# make mrproper //第一次编译无需运行此命令,如果之前有编译过,则需要
# cp /boot/config-`uname -r` .config //copy一份当前系统的内核配置文件作参考
# make menuconfig
下面两个需要选中(两个都选中),确保.config文件中有该项
CONFIG_SYSFS_DEPRECATED_V2 = y
否则编译完成重启系统时会有如下错误输出:
mount: could not find filesystem '/dev/root'
Setting up other filesystems.
Setting up new root fs
setuproot: moving /dev failed: No such file or directory
no fstab.sys, mounting internal defaults
setuproot: error mounting /proc: No such file or directory
setuproot: error mounting /sys: No such file or directory
Switching to new root and running init.
unmounting old /dev
unmounting old /proc
unmounting old /sys
switchroot: mount failed: No such file or directory
Kernel panic - not syncing: Attempted to kill init!
<a target="_blank" href="http://blog.51cto.com/attachment/201109/143744486.png"></a>
加上ext4的支持
<a target="_blank" href="http://blog.51cto.com/attachment/201109/144207400.png"></a>
然后保存即可
三、安装编译内核
# make all
# make modules_install
# make install
完了,修改grub启动文件,以新内核启动系统便可。
PS:如果这样就以新内核启动,系统重启时会报一个错误
insmod: error inserting ‘/lib/dm-region-hash.ko’: –1 File exits
这ms是2.6内核的Bug,需要修改内核,并重新生成新内核文件
解压修改内核步骤
# cp /boot/initrd-2.6.39.4.img /tmp/
# cd /tmp/
# mkdir newinitrd
# cd newinitrd/
# zcat ../initrd-2.6.39.4.img |cpio -i
# rm -f /tmp/initrd-2.6.39.4.img
# vi init
找到这4行一样的,去掉相同的2行
echo "Loading dm-region-hash.ko module"
insmod /lib/dm-region-hash.ko
重新打包内核
# find .|cpio -c -o >../initrd
# cd ..; gzip -9 < initrd > initrd-2.6.39.4.img
# cp initrd-2.6.39.4.img /boot/
本文转自dongfang_09859 51CTO博客,原文链接:http://blog.51cto.com/hellosa/658107,如需转载请自行联系原作者