服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

运维之家

 找回密码
 注册
搜索
查看: 6785|回复: 1

CentOS5内核版本升级

[复制链接]
dirtysea 发表于 2014-9-9 14:16:41 | 显示全部楼层 |阅读模式

yum -y install ncurses-devel 
cd /usr/src/kernels/ 
下载内核源码 
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.13.tar.bz2 
tar vxjf linux-3.2.13.tar.bz2 
cd linux-3.2.13 

make mrproper   清除环境变量,即清除配置文件 
make menuconfig 
请一定要加上下面的选项,你如果仅仅是想测试的话,别的不动都可以的。 

make menuconfig添加如下选项
General setup  ---> 

  • Enable deprecated sysfs features to support old userspace tools
  •    Enable deprecated sysfs features by default 

  • Device Drivers  --->   
      Serial ATA (prod) and Parallel ATA (experimental) drivers

    networking support—>networking options—>network packet filtering framework(netfilter)

    (1) core netfilter configuration
    A 勾中”Netfilter connection tracking support” -m state相关模块是依赖它的,不选则没有。
    B 将netbios name service protocal support(new) 编译成模块,不然后面升级iptables后启动时会出错
    C 勾中“Netfilter Xtables support (required for ip_tables)”
    (2) IP: Netfilter Configuration
    A 将 “IPv4 connection tracking support (require for NAT)” 编译成模块。
    B 勾中IP tables support (required for filtering/masq/NAT) 。
    C 将 “Full NAT” 下的 “MASQUERADE target support” 和 “REDIRECT target support” 编译成模块



    cp include/linux/hidraw.h /usr/include/linux/ 
    cp include/linux/hid.h /usr/include/linux/ 


    vim samples/hidraw/hid-example.c 

    在Linux下编译程序有时会遇到这种问题,这貌似是一个Linux历史遗留问题: 
    把所有#include <sys/xxx.h>都提到最前面,把#include <linux/xxx.h>的包含放在其后,就可以编译通过了,之所以出现面的问题是存在循环引用所致。 


    将13-15行的如下3行移动到33行以后。 

         13 #include <linux/types.h> 
         14 #include <linux/input.h> 
         15 #include <linux/hidraw.h> 

         29 #include <sys/ioctl.h> 
         30 #include <sys/types.h> 
         31 #include <sys/stat.h> 
         32 #include <fcntl.h> 
         33 #include <unistd.h> 

    vim /usr/include/linux/input.h 

    line 647 
    #define BUS_PCI                 0x01 
    #define BUS_ISAPNP              0x02 
    #define BUS_USB                 0x03 
    #define BUS_HIL                 0x04 
    #define BUS_BLUETOOTH           0x05 
    /*以下一行为新增*/ 
    #define BUS_VIRTUAL             0x06 

    #define BUS_ISA                 0x10 
    #define BUS_I8042               0x11 
    #define BUS_XTKBD               0x12 
    #define BUS_RS232               0x13 
    #define BUS_GAMEPORT            0x14 
    #define BUS_PARPORT             0x15 
    #define BUS_AMIGA               0x16 
    #define BUS_ADB                 0x17 
    #define BUS_I2C                 0x18 
    #define BUS_HOST                0x19 
    #define BUS_GSC                 0x1A 
    /*以下两行为新增*/ 
    #define BUS_ATARI               0x1B 
    #define BUS_SPI                 0x1C   


    make clean 确保所有东西均保持最新状态.

    make bzImage 生成内核文件

    make modules 编译模块

    make modules_install 安装模块

    make install 安装


    #设置使用新内核启动。 
    sed -i 's#default=1#default=0#g' grub.conf 

    ........test new kernel....... 

    uname -a 



    ---------------------------------------------------------------- 

    修改/boot/grub/grub.conf 里面有个default=0 0表示第一个,1表示第二个,一次类推。例如我的文件是这样的。 

    # 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/hda 
    default=0 
    timeout=5 
    splashimage=(hd0,0)/grub/splash.xpm.gz 
    hiddenmenu 
    title CentOS (2.6.25linux1610-2.6) 
            root (hd0,0) 
            kernel /vmlinuz-2.6.25linux1610-2.6 ro root=/dev/VolGroup00/LogVol00 
            initrd /initrd-2.6.25linux1610-2.6.img 
    title CentOS (2.6.18-92.el5) 
            root (hd0,0) 
            kernel /vmlinuz-2.6.18-92.el5 ro root=/dev/VolGroup00/LogVol00 
            initrd /initrd-2.6.18-92.el5.img 
    我的default=0,那么我就是默认启动下面这个我最新编译的了。 
    title CentOS (2.6.25linux1610-2.6) 
            root (hd0,0) 
            kernel /vmlinuz-2.6.25linux1610-2.6 ro root=/dev/VolGroup00/LogVol00 
            initrd /initrd-2.6.25linux1610-2.6.img 

     楼主| dirtysea 发表于 2014-9-10 09:37:38 | 显示全部楼层

    在实践过程中,我根本就没有手动去修改grub的配置信息,在运行make install命令的时候,就给帮你更新了grub的配置。

    先别急着重启机子,看看下面问题再说。

     

    解决问题

     


    内核升级的过程都是相似的,遇到的问题却各有各的不同。——KiKi

    问题1 
    问题描述:重启系统会报错”insmod: error inserting ‘/lib/dm-region-hash.ko’: –1 File exits”,

    原因: 在init文件中重复了insmod dm-region-hash.ko这条命令。

    解决方法:

    [root@localhost]cp /boot/initrd-2.6.30.img /tmp
    [root@localhost]cd /tmp/
    [root@localhost tmp]mkdir newinitrd
    [root@localhost tmp]cd newinitrd/
    [root@localhost newinitrd]zcat ../initrd-2.6.30.img |cpio -i
    [root@localhost newinitrd]vi init              删掉重复的如下两行:
    echo “Loading dm-region-hash.ko module”
    insmod /lib/dm-region-hash.ko
    [root@localhost newinitrd]# find .|cpio -c -o > ../initrd
    14765 blocks
    [root@localhost newinitrd]# cd ..
    [root@localhost tmp]# gzip -9 < initrd > initrd-2.6.30.img
    [root@localhost tmp]# ls
    gconfd-root   initrd   initrd-2.6.30.img   mapping-root   newinitrd   scim-panel-socket:0-root
    [root@localhost tmp]# mv /boot/initrd-2.6.30.img /home/
    [root@localhost tmp]# cp initrd-2.6.30.img /boot/
    [root@localhost tmp]#reboot


    问题2
    问题描述:重启之后却进不了系统。提示如下cound not find filesystem /dev/root.
    could not find filesystem /dev/root - nm - wzk_1 的博客

    原因有可能是:
    A:是由于无法加载磁盘硬件的模块驱动。
    解决方式主要是通过make menuconfig中加载sata scsi的devices设备模块驱动。

    # make menuconfig添加如下选项
    Device Drivers  --->   
      Serial ATA (prod) and Parallel ATA (experimental) drivers

    常用的驱动模块如下:

    insmod /lib/uhci-hcd.ko 
    insmod /libohci-hcd.ko 
    insmod /lib/ehci-hcd.ko 
    insmod /lib/jbd.ko
    insmod /lib/ext3.ko
    insmod /lib/scsi_mod.ko
    insmod /lib/sd_mod.ko
    insmod /lib/libata.ko
    insmod /lib/ahci.ko


    B:   initrd是旧版本mkinitrd生成的。

    解决方法就是加入对旧版sysfs路径的支持,方法如下:

    1)、通过make menuconfig选中以下对应的选项

    General setup –>              
    [*] enable deprecated sysfs features to support old userspace tools

    2)、修改.config文件

      修改.config文件中CONFIG_SYSFS_DEPRECATED_V2,将原本被注释掉的

           CONFIG_SYSFS_DEPRECATED_V2 改成CONFIG_SYSFS_DEPRECATED_V2=y

    注 :  修改这项是因为旧版的mkinitrd及其nash在内核没有CONFIG_SYSFS_DEPRECATED_V2参数时默认使用旧版sysfs路 径格式,从而在新内核下无法正确访问/sys内的硬盘信息节点。

     

    而本人是因为在编译内核的时候,没有添加sata硬盘的内核驱动模块,导致系统无法识别SATA硬盘,所以没法进入系统。属于原因A。

    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    QQ|小黑屋|手机版|Archiver|运维之家

    GMT+8, 2024-3-29 07:58 , Processed in 0.156472 second(s), 17 queries .

    Powered by Dirtysea

    © 2008-2020 Dirtysea.com.

    快速回复 返回顶部 返回列表