Linux内核升级
一、测试环境
CentOS6.5 X86 64位 内核版本为 2.6.32
VM 10.07
二、编译内核版本
2.1、kernel 3.2.71
2.2、kernel 3.4.108
2.3、kernel 4.2
三、编译步骤
3.1、编译环境的安装
# yum grouplist 检查已安装和未安装的开发环境和相应的库
# yum groupinstall "Development Tools" 安装编译时所需的工具软件
# yum install ncurses-devel
# yum install qt-devel
# yum install hmaccalc zlib-devel binutils-devel elfutils-libelf-devel openssl-devel bc
3.2、解压内核文件
注:这里上传内核文件的目录为/home/soft
# cd /home/soft
# xz –d linux-3.2.71.tar.xz
# tar xvf linux-3.2.71.tar
# cd linux-3.2.71
3.3、配置内核
# make menuconfig
说明:定制自己的内核,会生成新的.config文件,这里用原来的内核配置
# cp /boot/config-2.6.32-431.el6.x86_64 .config
#sh -c \'yes "" | make oldconfig\'
3.4、编译内核
#make -j4 bzImage #编译内核
#make -j4 modules #编译模块
#make -j4 modules_install #安装模块
#make install #安装
说明:-j 指的是线程数
3.5、修改启动项
# Vi /etc/grub.conf
Default=x
说明:x就是你内核所在的启动项,可以根据实际填写
注:centos7 修改内核启动顺序
[root@node-4 linux-4.20]# cat /boot/grub2/grub.cfg | grep menuentry //查看可用内核
menuentry \'CentOS Linux (4.20.0) 7 (Core)\'
[root@node-4 linux-4.20]# grub2-set-default \'CentOS Linux (4.20.0) 7 (Core)\' //修改默认内核
内核5.x升级报错处理:
1.modules.order:No such file or directory
=>make modules #集合modules,生成modules.order
2.make[1]: *** No rule to make target \'certs/rhel.pem\', needed by \'certs/x509_certificate_list\'. Stop.
make: *** [Makefile:1729: certs] Error 2
=> 打开.config,注释掉这一行
CONFIG_SYSTEM_TRUSTED_KEYS="certs/rhel.pem"
3.BTF: .tmp_vmlinux.btf: pahole (pahole) is not available
Failed to generate BTF for vmlinux
Try to disable CONFIG_DEBUG_INFO_BTF
make: *** [Makefile:1113: vmlinux] Error 1
=>修改CONFIG_DEBUG_INFO_BTF=n
GCC升级步骤:
升级到gcc 6.3:devtoolset-6已经结束支持,请安装devtoolset-7
需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。如果要长期使用gcc 6.3的话:
这样退出shell重新打开就是新版的gcc了以下其他版本同理,修改devtoolset版本号即可。
VPS侦探 https://www.vpser.net
升级到gcc 7.3:
yum -y install centos-release-scl
yum -y install devtoolset-7-gcc devtoolset-7-gcc-c++ devtoolset-7-binutils
scl enable devtoolset-7 bash
yum -y install devtoolset-7-gcc devtoolset-7-gcc-c++ devtoolset-7-binutils
scl enable devtoolset-7 bash
需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。
如果要长期使用gcc 7.3的话:
echo "source /opt/rh/devtoolset-7/enable" >>/etc/profile
升级到gcc 8.3:
yum -y install centos-release-scl
yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
scl enable devtoolset-7 bash
yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
scl enable devtoolset-7 bash
需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。
如果要长期使用gcc 8.3的话:
echo "source /opt/rh/devtoolset-8/enable" >>/etc/profile
升级到gcc 9.3:
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。
如果要长期使用gcc 9.3的话:
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
再说一下已经停止支持的devtoolset4(gcc 5.2)及之前版本的安装方法
升级到gcc 4.8:
wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtoolset-2.repo
yum -y install devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils
scl enable devtoolset-2 bash
yum -y install devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils
scl enable devtoolset-2 bash
升级到gcc4.9:
wget https://copr.fedoraproject.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo -O /etc/yum.repos.d/devtoolset-3.repo
yum -y install devtoolset-3-gcc devtoolset-3-gcc-c++ devtoolset-3-binutils
scl enable devtoolset-3 bash
yum -y install devtoolset-3-gcc devtoolset-3-gcc-c++ devtoolset-3-binutils
scl enable devtoolset-3 bash
升级到gcc 5.2
wget https://copr.fedoraproject.org/coprs/hhorak/devtoolset-4-rebuild-bootstrap/repo/epel-6/hhorak-devtoolset-4-rebuild-bootstrap-epel-6.repo -O /etc/yum.repos.d/devtoolset-4.repo
yum install devtoolset-4-gcc devtoolset-4-gcc-c++ devtoolset-4-binutils -y
scl enable devtoolset-4 bash
yum install devtoolset-4-gcc devtoolset-4-gcc-c++ devtoolset-4-binutils -y
scl enable devtoolset-4 bash
升级完成后一定要运行:gcc --version 看一下版本号变成升级后的gcc版本才算升级成功。
CentOS8操作:
设置以新内核启动
[root@k8s-node-1 linux-5.9.2]# grub2-set-default 0
生成grub文件
[root@k8s-node-1 linux-5.9.2]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
done