有时因为系统内核的bug 我们必须要安装新版本的kernel 来解决问题,有几种方法
- 源码编译
- 使用编译好的包
使用包的方式比较方便,同时一些依赖的问题可以自动帮助我们处理
添加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
启用repo
可以通过修改文件
/etc/yum.repos.d/elrepo.repo 参考如下
[elrepo-kernel]
name=ELRepo.org Community Enterprise Linux Kernel Repository - el7
baseurl=http://elrepo.org/linux/kernel/el7/$basearch/
http://mirrors.coreix.net/elrepo/kernel/el7/$basearch/
http://mirror.rackspace.com/elrepo/kernel/el7/$basearch/
http://repos.lax-noc.com/elrepo/kernel/el7/$basearch/
http://mirror.ventraip.net.au/elrepo/kernel/el7/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-kernel.el7
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0
或者
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
刷新cache
yum clean dbcache
yum makecache
安装
yum install -y kernel-lt or yum install -y kernel-ml
修改grub 启动
- 修改文件
/etc/default/grub 并设置 GRUB_DEFAULT=0, 让GRUB 初始化页面的第一个内核将作为默认内核。
GRUB_TIMEOUT=1
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto noibrs idle=halt net.ifnames=0 console=tty0 console=ttyS0,115200n8"
GRUB_DISABLE_RECOVERY="true"
- 重新创建内核配置
grub2-mkconfig -o /boot/grub2/grub.cfg
效果
grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file
Found linux image: /boot/vmlinuz-5.1.5-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.1.5-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-4.4.180-2.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.4.180-2.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.5.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.5.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.1.3.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.1.3.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-862.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-862.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-20181212155109274552296824485474
Found initrd image: /boot/initramfs-0-rescue-20181212155109274552296824485474.img
done
- 重启系统
reboot
- 查看效果
uname -a
Linux iZ2zeg7uro1snhd9wqmp2oZ 5.1.5-1.el7.elrepo.x86_64 #1 SMP Sat May 25 16:10:51 EDT 2019 x86_64 x86_64 x86_64 GNU/Linux