dnf 静默更新

0 阅读1分钟

1. 手动执行深度清理

貌似没用,等下次修的时候改一下

手动清理一次旧内核和无用依赖。

# 一键清理缓存、孤立依赖并只保留最近2个内核
sudo dnf clean all && \
sudo dnf autoremove -y && \
sudo dnf remove $(dnf repoquery --installonly --latest-limit=-2) -y

2. 配置 dnf-automatic

安装并配置官方的自动更新工具。

安装服务

sudo dnf install dnf-automatic

修改配置

编辑 /etc/dnf/automatic.conf,确保以下核心项已正确设置:

  • upgrade_type = default:更新所有软件包。
  • download_updates = yes:自动下载。
  • apply_updates = yes:核心项,设为 yes 才会自动安装。
  • clean_requirement_on_remove = yes:自动清理不再需要的依赖。
  • emit_via = none:实现完全静默,不发送通知。

3. 启用定时任务

由于系统可能仅包含通用定时器,直接启用 dnf-automatic.timer 即可。它会根据上述配置文件执行安装任务。

# 启动并开机自启定时器
sudo systemctl enable --now dnf-automatic.timer

4. 维护与检查

  • 查看任务计划:systemctl list-timers dnf-automatic*
  • 查看服务状态:systemctl status dnf-automatic.timer
  • 内核保留设置:如需长期控制内核数量,可在 /etc/dnf/dnf.conf 中修改 installonly_limit=3