centos 编译内核至2.6.39.4

未分类

一、下载内核文件并解压至相应目录

  1. # wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.4.tar.bz2
  2. # tar jxvf linux-2.6.39.4.tar.bz2
  3. # mv linux-2.6.39.4 /usr/src

二、简要的配置内核

  1. # cd /usr/src/linux-2.6.39.4
  2. # make mrproper //第一次编译无需运行此命令,如果之前有编译过,则需要
  3. # cp /boot/config-`uname -r` .config //copy一份当前系统的内核配置文件作参考
  4. # make menuconfig

下面两个需要选中(两个都选中),确保.config文件中有该

  1. CONFIG_SYSFS_DEPRECATED_V2 = y

否则编译完成重启系统时会有如下错误输出:

  1. mount: could not find filesystem ‘/dev/root’
  2. Setting up other filesystems.
  3. Setting up new root fs
  4. setuproot: moving /dev failed: No such file or directory
  5. no fstab.sys, mounting internal defaults
  6. setuproot: error mounting /proc: No such file or directory
  7. setuproot: error mounting /sys: No such file or directory
  8. Switching to new root and running init.
  9. unmounting old /dev
  10. unmounting old /proc
  11. unmounting old /sys
  12. switchroot: mount failed: No such file or directory
  13. Kernel panic – not syncing: Attempted to kill init!

加上ext4的支持

然后保存即可

三、安装编译内核

  1. # make all
  2. # make modules_install
  3. # make install

完了,修改grub启动文件,以新内核启动系统便可。

PS:如果这样就以新内核启动,系统重启时会报一个错误

  1. insmod: error inserting ‘/lib/dm-region-hash.ko’: –1 File exits

这ms是2.6内核Bug,需要修改内核,并重新生成新内核文件

解压修改内核步骤

  1. # cp /boot/initrd-2.6.39.4.img /tmp/
  2. # cd /tmp/
  3. # mkdir newinitrd
  4. # cd newinitrd/
  5. # zcat ../initrd-2.6.39.4.img |cpio -i
  6. # rm -f /tmp/initrd-2.6.39.4.img
  7. # vi init
  8. 找到这4行一样的,去掉相同的2行
  9. echo “Loading dm-region-hash.ko module”
  10. insmod /lib/dm-region-hash.ko
  11. echo “Loading dm-region-hash.ko module”
  12. insmod /lib/dm-region-hash.ko

重新打包内核

  1. # find .|cpio -c -o >../initrd
  2. # cd ..; gzip -9 < initrd > initrd-2.6.39.4.img
  3. # cp initrd-2.6.39.4.img /boot/