diff --git a/scripts/system_optimize.sh b/scripts/system_optimize.sh index 25b71ac..37148e4 100644 --- a/scripts/system_optimize.sh +++ b/scripts/system_optimize.sh @@ -57,6 +57,25 @@ synchronize_hardware_clock() { # log_info "已尝试删除'ubuntu'用户(如果存在)" #} +#锁定版本号 +lock_current_kernel(){ + # 自动锁定当前运行的内核版本 + CURRENT_KERNEL=$(uname -r) + GRUB_FILE="/etc/default/grub" + + # 检查是否已锁定 + if ! grep -q "GRUB_DEFAULT=.*$CURRENT_KERNEL" "$GRUB_FILE"; then + # 备份并修改GRUB配置 + cp -f "$GRUB_FILE" "${GRUB_FILE}.bak" + sed -i '/GRUB_DEFAULT=/c\GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux '${CURRENT_KERNEL}'"' "$GRUB_FILE" + update-grub &>/dev/null + echo "已锁定内核版本: $CURRENT_KERNEL" + echo "稍后记得执行 'reboot' 重启系统!" + else + echo "内核版本 $CURRENT_KERNEL 已锁定,无需操作" + fi +} + # 禁止显卡驱动 disable_nouveau_driver() { log_info "禁止nouveau显卡驱动..." @@ -110,13 +129,12 @@ update_grub_configuration() { # 主函数:按顺序执行所有配置步骤 main() { log_info "开始系统配置..." - disable_apt_periodic_updates set_timezone_to_shanghai + lock_current_kernel synchronize_hardware_clock disable_nouveau_driver update_grub_configuration - log_info "系统配置完成!" }