环境:
系统硬件:vmware vsphere (CPU:1*1核,内存2G)
系统版本:Linux centos 2.6.32-431.el6.x86_64(Centos-6.5-x86_64-minimal.iso )
升级内核版本:longterm:3.16.68
升级步骤:
1.查看原有系统内核版本
[root@centos ~]# uname -r
2.升级更新包
[root@centos ~]# yum update
[root@centos ~]# yum upgrade
3.安装编译环境所需要的工具包
[root@centos ~]# yum install vim wget
[root@centos ~]# yum install gcc gcc-c++ xz
[root@centos ~]# yum install bc
[root@centos ~]# yum install ncurses-devel
[root@centos ~]# yum install hmaccalc zlib-devel binutils-devel elfutils-libelf-devel
4.下载内核源码包
去 https://www.kernel.org/ 可以看到有stable, longterm等版本,longterm是比stable更稳定的版本,会长时间更新,因此我选择 3.16.68。
[root@centos ~]# wget https://cdn.kernel.org/pub/linux/kernel/v3.x/linux-3.16.68.tar.xz
[root@centos ~]# tar -xf linux-3.16.68.tar.xz -C /usr/local/src/
[root@centos ~]# cd /usr/local/src/linux-3.16.68/
[root@centos linux-3.16.68]# cp /boot/config-2.6.32-431.el6.x86_64 .config
#在系统原有的内核配置文件的基础上建立新的编译选项,所以复制一份到当前目录下,命名为.config
[root@centos linux-3.16.68]# sh -c ‘yes “” | make oldconfig’
#make oldconfig会读取当前目录下的.config文件,在.config文件里没有找到的选项则提示用户填写,然后备份.config文件为.config.old,并生成新的.config文件
5.开始编译
[root@centos linux-3.16.68]# make -j4 bzImage #生成内核文件
[root@centos linux-3.16.68]# make -j4 modules #编译模块
[root@centos linux-3.16.68]# make -j4 modules_install #编译安装模块
#-j后面的数字是线程数,用于加快编译速度
6.安装
[root@centos linux-3.16.68]# make install
#实际运行到这一步时,出现ERROR: modinfo: could not find module vmware_balloon,但是不影响内核安装,是由于vsphere需要的模块没有编译,要避免这个问题,需要在make之前时修改.config文件,加入
HYPERVISOR_GUEST=y CONFIG_VMWARE_BALLOON=m
7.更改系统启动时,使用的内核
[root@centos ~]# vim /boot/grub/menu.lst
修改default=0,开机后,默认以第一项启动(3.16.68内核) 保存退出
8.重启系统
[root@centos ~]# shutdown -r now
9.确认当前内核版本
[root@centos ~]# uname -r
Linux centos65 3.16.68 #1 SMP Wed May 29 23:43:48 CST 2019 x86_64
x86_64 x86_64 GNU/Linux显示内核为3.16.68,表示升级内核成功