centos7 shell脚本一键升级内核
因为之前安装jumpserver的时候,需要升级系统内核到4.x及以上,故写了个一键升级内核脚本.
系统:centos 7.x(64位)
cat /root/soft_shell/update_kernel.sh
#!/bin/bash #一键升级centos7内核 # Check if user is root if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script, please use root to initialization OS." exit 1 fi if [ "$(awk '{if ( $3 >= 7.0 ) print "CentOS 7.x"}' /etc/redhat-release 2>/dev/null)" != "CentOS 7.x" ];then err_echo "This script is used for RHEL/CentOS 7.x only." exit 1 fi package=`rpm -qa |grep elrepo|awk -F "-" '{print $1}'` if [ -z $package ];then rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm else echo -e "\033[40;31m elrepo [found]\033[40;37m" fi # 仓库启用后,你可以使用下面的命令列出可用的内核相关包,如下图: yum --disablerepo="*" --enablerepo="elrepo-kernel" list available # 安装长期维护版本lt,最新主线稳定版ml yum -y --enablerepo=elrepo-kernel install kernel-lt if [ $? -eq 0 ];then Version=`awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg | head -1` grub2-set-default "$Version" echo -e "Restart the system after 3 seconds..." && sleep 3 init 6 else echo "exec failure..." exit 0 fi
系统重启后,就可以执行uname -r来看内核是否是最新的版本了.
评论: