Centos7 更换内核到4.16的尝试

背景:

  特殊需求,需要使用kernel 4.x版本,在云上ECS如何更换呢?
  

怂一下先:
请对生产环境,保持敬畏之心,务必做好快照备份!
请对生产环境,保持敬畏之心,务必做好快照备份!
请对生产环境,保持敬畏之心,务必做好快照备份!

1,看下内核先

# uname -r
3.10.0-514.26.2.el7.x86_64

2,升级内核需要先导入elrepo的key,然后安装elrepo的yum源:

# rpm -import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
#  rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
Retrieving http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
Retrieving http://elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:elrepo-release-7.0-3.el7.elrepo  ################################# [100%]

3,看下源上的内核版本

# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror
elrepo-kernel                                                                                           | 2.9 kB  00:00:00     
elrepo-kernel/primary_db       FAILED                                                        ] 4.1 kB/s |  83 kB  00:06:58 ETA 
http://elrepo.org/linux/kernel/el7/x86_64/repodata/b970175c81e43b64f8ed487034e08db0f81ba50f2ba1a770606d4a85f7c3c1ab-primary.sqlite.bz2: [Errno 14] curl#18 - "transfer closed with 1740046 bytes remaining to read"
Trying other mirror.
elrepo-kernel/primary_db       FAILED                                          
http://mirrors.coreix.net/elrepo/kernel/el7/x86_64/repodata/b970175c81e43b64f8ed487034e08db0f81ba50f2ba1a770606d4a85f7c3c1ab-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.coreix.net; Unknown error"
Trying other mirror.
elrepo-kernel/primary_db                                                                                | 1.7 MB  00:00:02     
Determining fastest mirrors
 * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
Available Packages
kernel-lt.x86_64                                               4.4.131-1.el7.elrepo                               elrepo-kernel
kernel-lt-devel.x86_64                                         4.4.131-1.el7.elrepo                               elrepo-kernel
kernel-lt-doc.noarch                                           4.4.131-1.el7.elrepo                               elrepo-kernel
kernel-lt-headers.x86_64                                       4.4.131-1.el7.elrepo                               elrepo-kernel
kernel-lt-tools.x86_64                                         4.4.131-1.el7.elrepo                               elrepo-kernel
kernel-lt-tools-libs.x86_64                                    4.4.131-1.el7.elrepo                               elrepo-kernel
kernel-lt-tools-libs-devel.x86_64                              4.4.131-1.el7.elrepo                               elrepo-kernel
kernel-ml.x86_64                                               4.16.8-1.el7.elrepo                                elrepo-kernel
kernel-ml-devel.x86_64                                         4.16.8-1.el7.elrepo                                elrepo-kernel
kernel-ml-doc.noarch                                           4.16.8-1.el7.elrepo                                elrepo-kernel
kernel-ml-headers.x86_64                                       4.16.8-1.el7.elrepo                                elrepo-kernel
kernel-ml-tools.x86_64                                         4.16.8-1.el7.elrepo                                elrepo-kernel
kernel-ml-tools-libs.x86_64                                    4.16.8-1.el7.elrepo                                elrepo-kernel
kernel-ml-tools-libs-devel.x86_64                              4.16.8-1.el7.elrepo                                elrepo-kernel
perf.x86_64                                                    4.16.8-1.el7.elrepo                                elrepo-kernel
python-perf.x86_64                                             4.16.8-1.el7.elrepo                                elrepo-kernel

4,安装内核

# yum -y --enablerepo=elrepo-kernel install kernel-ml.x86_64 kernel-ml-devel.x86_64 

Centos7 更换内核到4.16的尝试
版本性质:主分支ml(mainline),稳定版(stable),长期维护版lt(longterm)

5,查看内核是否安装完成

# rpm -qa |grep kernel
kernel-ml-devel-4.16.8-1.el7.elrepo.x86_64
kernel-3.10.0-327.el7.x86_64
kernel-headers-3.10.0-514.26.2.el7.x86_64
kernel-ml-4.16.8-1.el7.elrepo.x86_64
kernel-3.10.0-514.26.2.el7.x86_64
kernel-tools-libs-3.10.0-514.26.2.el7.x86_64
kernel-tools-3.10.0-514.26.2.el7.x86_64

6,查看并修改grub的启动顺序

# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
CentOS Linux (4.16.8-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux (3.10.0-514.26.2.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-36dc953195bb4389870d2591ff6bfea5) 7 (Core)

注:第一个是4.16,但是对应的顺序是0

# vi /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved(这里改成0)
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet net.ifnames=0 console=tty0 console=ttyS0,115200n8"
GRUB_DISABLE_RECOVERY="true"

7,生成grub重新创建内核配置并重启

# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.16.8-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.16.8-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-514.26.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.26.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-36dc953195bb4389870d2591ff6bfea5
Found initrd image: /boot/initramfs-0-rescue-36dc953195bb4389870d2591ff6bfea5.img
done

# reboot

8,重启成功后登陆确认内核版本

# uname -r
4.16.8-1.el7.elrepo.x86_64

更换成功~请务必做好新内核的测试,再考虑生产环境的更换

上一篇:记一次IO异常捕获的过程


下一篇:IPV6之ECS初尝试