__kernel_update() {
#导入公钥
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
#添加YUM源
yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
#安装更新长期支持版内核
yum install -y --enablerepo=elrepo-kernel kernel-lt kernel-lt-devel
#更新GRUB配置使用新内核启动
#查看配置中的所有内核版本
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
_modify=$(awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg | head -1 | grep "$(uname -r)" -c)
if ((_modify != 1)); then
#设置新内核为默认启动项,默认情况下新内核序号为0
grub2-set-default 0
#更新配置
grub2-mkconfig -o /boot/grub2/grub.cfg
# 设置开机免输入密码
sed -i 's,^ExecStart=.*$,ExecStart=-/sbin/agetty --autologin root --noclear %I,' /etc/systemd/system/getty.target.wants/getty@tty1.service
sed -i 's,^ExecStart=.*$,ExecStart=-/sbin/agetty --autologin root --noclear %I,' /lib/systemd/system/autovt@.service
# 修改系统启动等待时间
sed -i 's,timeout=5$,timeout=2,' /boot/grub2/grub.cfg
sed -i 's,timeout=5$,timeout=2,' /boot/efi/EFI/centos/grub.cfg
sync
# reboot
fi
}
__kernel_update
参考文档
http://blog.itpub.net/6906/viewspace-2657192/
https://www.jianshu.com/p/e20863f365c4
https://blog.csdn.net/zxloveooo/article/details/104921010