自学内容网 自学内容网

Ubuntu 更换内核版本

更换内核脚本

这里以更换 5.15.0-88-generic 版本内核为例

cat kernel.sh
#!/bin/bash

apt install linux-image-5.15.0-88-generic
# Ubuntu内核切换脚本

# 检查是否具有root权限
if [[ $(id -u) -ne 0 ]]; then
          echo "请以root身份运行此脚本。"
            exit 1
fi

# 检查系统是否为Ubuntu
if [[ ! -f /etc/lsb-release ]]; then
          echo "此脚本仅适用于Ubuntu系统。"
            exit 1
fi

# 检查内核是否已安装
if [[ ! -f /boot/vmlinuz-5.15.0-88-generic ]]; then
          echo "内核版本5.15.0-88-generic未安装,请先安装该内核版本。"
            exit 1
fi

# 更新GRUB引导
echo "正在更新GRUB引导..."
update-grub

# 设置默认启动内核为5.15.0-88-generic
echo "设置默认启动内核为5.15.0-88-generic..."
sed -i 's/GRUB_DEFAULT=.*/GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-88-generic"/' /etc/default/grub

# 更新GRUB配置
update-grub

echo "内核切换完成,请重新启动系统以应用更改。"

执行脚本

bash kernel.sh

重启系统

reboot

原文地址:https://blog.csdn.net/weixin_40548182/article/details/142827990

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!