本文共 5595 字,大约阅读时间需要 18 分钟。
背景:
特殊需求,需要使用kernel 4.x版本,在云上ECS如何更换呢?
怂一下先:
请对生产环境,保持敬畏之心,务必做好快照备份! 请对生产环境,保持敬畏之心,务必做好快照备份! 请对生产环境,保持敬畏之心,务必做好快照备份!1,看下内核先
# uname -r3.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.rpmRetrieving http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpmRetrieving http://elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpmPreparing... ################################# [100%]Updating / installing... 1:elrepo-release-7.0-3.el7.elrepo ################################# [100%]
3,看下源上的内核版本
# yum --disablerepo="*" --enablerepo="elrepo-kernel" list availableLoaded plugins: fastestmirrorelrepo-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.cnAvailable Packageskernel-lt.x86_64 4.4.131-1.el7.elrepo elrepo-kernelkernel-lt-devel.x86_64 4.4.131-1.el7.elrepo elrepo-kernelkernel-lt-doc.noarch 4.4.131-1.el7.elrepo elrepo-kernelkernel-lt-headers.x86_64 4.4.131-1.el7.elrepo elrepo-kernelkernel-lt-tools.x86_64 4.4.131-1.el7.elrepo elrepo-kernelkernel-lt-tools-libs.x86_64 4.4.131-1.el7.elrepo elrepo-kernelkernel-lt-tools-libs-devel.x86_64 4.4.131-1.el7.elrepo elrepo-kernelkernel-ml.x86_64 4.16.8-1.el7.elrepo elrepo-kernelkernel-ml-devel.x86_64 4.16.8-1.el7.elrepo elrepo-kernelkernel-ml-doc.noarch 4.16.8-1.el7.elrepo elrepo-kernelkernel-ml-headers.x86_64 4.16.8-1.el7.elrepo elrepo-kernelkernel-ml-tools.x86_64 4.16.8-1.el7.elrepo elrepo-kernelkernel-ml-tools-libs.x86_64 4.16.8-1.el7.elrepo elrepo-kernelkernel-ml-tools-libs-devel.x86_64 4.16.8-1.el7.elrepo elrepo-kernelperf.x86_64 4.16.8-1.el7.elrepo elrepo-kernelpython-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版本性质:主分支ml(mainline),稳定版(stable),长期维护版lt(longterm)
5,查看内核是否安装完成
# rpm -qa |grep kernelkernel-ml-devel-4.16.8-1.el7.elrepo.x86_64kernel-3.10.0-327.el7.x86_64kernel-headers-3.10.0-514.26.2.el7.x86_64kernel-ml-4.16.8-1.el7.elrepo.x86_64kernel-3.10.0-514.26.2.el7.x86_64kernel-tools-libs-3.10.0-514.26.2.el7.x86_64kernel-tools-3.10.0-514.26.2.el7.x86_64
6,查看并修改grub的启动顺序
# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfgCentOS 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=5GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"GRUB_DEFAULT=saved(这里改成0)GRUB_DISABLE_SUBMENU=trueGRUB_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.cfgGenerating grub configuration file ...Found linux image: /boot/vmlinuz-4.16.8-1.el7.elrepo.x86_64Found initrd image: /boot/initramfs-4.16.8-1.el7.elrepo.x86_64.imgFound linux image: /boot/vmlinuz-3.10.0-514.26.2.el7.x86_64Found initrd image: /boot/initramfs-3.10.0-514.26.2.el7.x86_64.imgFound linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.imgFound linux image: /boot/vmlinuz-0-rescue-36dc953195bb4389870d2591ff6bfea5Found initrd image: /boot/initramfs-0-rescue-36dc953195bb4389870d2591ff6bfea5.imgdone# reboot
8,重启成功后登陆确认内核版本
# uname -r4.16.8-1.el7.elrepo.x86_64
更换成功~请务必做好新内核的测试,再考虑生产环境的更换
转载地址:http://gchlx.baihongyu.com/