Upgrade Debian 12 to 13 Without Rushing the Risky Parts
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
A major Debian upgrade is more than changing a repository name. APT may replace core packages, restart services, and remove packages to resolve dependencies. If the machine is remote, a mistake can also leave you without SSH access. For Debian 12 (Bookworm) to Debian 13 (Trixie), the safer sequence is: prepare recovery, fully update Bookworm, change supported Debian sources, run the upgrade in two stages, then reboot and verify.
Debian 的重大版本升级不仅仅是更改存储库名称。APT 可能会替换核心软件包、重启服务并删除软件包以解决依赖关系。如果机器是远程的,操作失误可能会导致你失去 SSH 访问权限。对于从 Debian 12 (Bookworm) 到 Debian 13 (Trixie) 的升级,更安全的顺序是:准备恢复方案、完全更新 Bookworm、更改受支持的 Debian 源、分两个阶段运行升级,然后重启并验证。
Before changing anything Start with a backup or VM snapshot you know how to restore. If this is a remote server, confirm that you can reach its provider console or another out-of-band recovery method. A persistent terminal session such as tmux or screen, if installed, can help if your SSH connection drops—but it is not a substitute for recovery access. Check the installed release, available space, and package holds: cat /etc/os-release df -h / /var /boot apt-mark showhold Pay particular attention to /boot if it is a separate, small filesystem. A new kernel and initramfs need room. This guide to checking disk space on Linux explains how to investigate capacity before an upgrade. Review held packages and locally installed software that depends on third-party repositories. A hold may be intentional; don’t remove it without understanding why. Check that critical vendor packages support Debian 13.
在进行任何更改之前,请先进行备份或确保你知道如何恢复虚拟机快照。如果是远程服务器,请确认你可以访问其提供商控制台或其他带外恢复方法。如果已安装,tmux 或 screen 等持久终端会话可以在 SSH 连接断开时提供帮助,但这不能替代恢复访问权限。检查已安装的版本、可用空间和软件包保留状态:cat /etc/os-release、df -h / /var /boot、apt-mark showhold。如果 /boot 是一个独立的小型文件系统,请特别注意它。新的内核和 initramfs 需要空间。这份关于检查 Linux 磁盘空间的指南解释了如何在升级前调查容量。检查保留的软件包以及依赖第三方存储库的本地安装软件。保留可能是故意的;在不了解原因的情况下,不要删除它。检查关键的供应商软件包是否支持 Debian 13。
Bring Bookworm fully up to date Do not switch releases while Bookworm still has unexplained pending updates or dependency problems. First update the current release: sudo apt update sudo apt upgrade Review APT’s proposed changes before confirming. Resolve errors or held-package conflicts while the machine is still on Debian 12. If a kernel or other core package was updated, reboot if appropriate, then verify the system is healthy before continuing. Run commands without sudo if you are already in a root shell.
将 Bookworm 完全更新到最新状态。在 Bookworm 仍有无法解释的待处理更新或依赖问题时,请勿切换版本。首先更新当前版本:sudo apt update、sudo apt upgrade。在确认之前,请审查 APT 提出的更改。在机器仍处于 Debian 12 时解决错误或保留软件包的冲突。如果内核或其他核心软件包已更新,请在适当的情况下重启,然后在继续之前验证系统是否健康。如果你已经在 root shell 中,则无需使用 sudo 运行命令。
Update the right APT sources Debian repository definitions can be in /etc/apt/sources.list, files under /etc/apt/sources.list.d/, or both. Newer installations may use deb822 files ending in .sources, where the release appears in a Suites: field rather than a deb line. Find files mentioning Debian release names: grep -RInE ‘bookworm|bullseye|trixie’ \ /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null Inspect the results individually. For Debian repositories, change the relevant Bookworm suite to Trixie while preserving the repository URL, components, and other applicable settings. Review security and updates entries too. Don’t blindly replace every occurrence of bookworm: a third-party vendor may not provide a Trixie repository, and changing its suite name does not make it compatible. Make a copy of source files before editing. Temporarily disable third-party sources if their Debian 13 support is unclear, and keep notes so you can revisit them later. After editing, check that the active Debian entries point to the intended release and that no unintended older-release entries remain. If the source layout is confusing, stop and consult the official Debian 13 upgrade notes rather than guessing.
更新正确的 APT 源。Debian 存储库定义可能位于 /etc/apt/sources.list、/etc/apt/sources.list.d/ 下的文件中,或两者兼有。较新的安装可能使用以 .sources 结尾的 deb822 文件,其中版本出现在 Suites: 字段中,而不是 deb 行中。查找提及 Debian 版本名称的文件:grep -RInE ‘bookworm|bullseye|trixie’ /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null。逐一检查结果。对于 Debian 存储库,将相关的 Bookworm 套件更改为 Trixie,同时保留存储库 URL、组件和其他适用设置。同时审查安全和更新条目。不要盲目替换每一个 bookworm:第三方供应商可能不提供 Trixie 存储库,更改其套件名称并不能使其兼容。编辑前请备份源文件。如果第三方源对 Debian 13 的支持不明确,请暂时禁用它们,并做好笔记以便稍后重新访问。编辑后,检查活动的 Debian 条目是否指向预期的版本,并且没有残留意外的旧版本条目。如果源布局令人困惑,请停止并查阅官方的 Debian 13 升级说明,而不是进行猜测。
Run the upgrade in two stages Refresh package lists first: sudo apt update Do not continue if this reports missing Release files, signature errors, or other repository failures. Fix the source definitions before installing packages. Then perform the minimal upgrade: sudo apt upgrade —without-new-pkgs Read the proposed package plan. This step upgrades packages where possible without installing new packages or removing packages to resolve dependency changes. Pause if APT proposes removing essential software or making changes you don’t understand. Next, complete the transition: sudo apt full-upgrade Unlike a plain apt upgrade, full-upgrade can install new dependencies and remove packages when needed. Review removals carefully before accepting. During the upgrade, configuration prompts may ask whether to keep a locally modified file or install the package maintainer’s version. Compare the options; preserving a custom SSH, network, or service configuration may be important. Keep the terminal open until APT finishes. If the session disconnects, check whether the package operation is still running before starting another one. Don’t reboot in the middle of an active package operation.
分两个阶段运行升级。首先刷新软件包列表:sudo apt update。如果报告缺少 Release 文件、签名错误或其他存储库故障,请勿继续。在安装软件包之前修复源定义。然后执行最小升级:sudo apt upgrade —without-new-pkgs。阅读建议的软件包计划。此步骤在可能的情况下升级软件包,而无需安装新软件包或删除软件包以解决依赖关系更改。如果 APT 建议删除基本软件或进行你不理解的更改,请暂停。接下来,完成转换:sudo apt full-upgrade。与普通的 apt upgrade 不同,full-upgrade 可以在需要时安装新依赖项并删除软件包。在接受之前仔细审查删除项。在升级过程中,配置提示可能会询问是保留本地修改的文件还是安装软件包维护者的版本。比较这些选项;保留自定义的 SSH、网络或服务配置可能很重要。保持终端打开直到 APT 完成。如果会话断开,请在启动另一个操作之前检查软件包操作是否仍在运行。不要在活跃的软件包操作过程中重启。
Reboot and verify Once APT finishes without errors, reboot when you have an appropriate maintenance window: sudo reboot After the server returns, check the release, running kernel, and package sources: cat /etc/os-release uname -r sudo apt update apt list —upgradable /etc/os-release should identify Debian GNU/Linux 13, also known as Trixie. uname -r shows the kernel currently running; it can differ from a newly installed kernel if the reboot did not complete as expected. Check SSH access, networking, scheduled jobs, and the applications that matter on this machine. For systemd services, inspect their status and logs if anything failed. If SSH itself needs attention, use a safe sequence to restart the SSH service on Linux rather than assuming a restart will solve every connection issue. Re-enable third-party repositories only after confirming that the vendor supports Trixie. Then check whether the software needs a separate upgrade or migration step.
重启并验证。一旦 APT 无错误完成,请在适当的维护窗口重启:sudo reboot。服务器恢复后,检查版本、运行中的内核和软件包源:cat /etc/os-release、uname -r、sudo apt update、apt list —upgradable。/etc/os-release 应标识为 Debian GNU/Linux 13,也称为 Trixie。uname -r 显示当前运行的内核;如果重启未按预期完成,它可能与新安装的内核不同。检查 SSH 访问、网络、计划任务以及这台机器上重要的应用程序。对于 systemd 服务,如果出现故障,请检查其状态和日志。如果 SSH 本身需要注意,请使用安全序列重启 Linux 上的 SSH 服务,而不是假设重启能解决所有连接问题。仅在确认供应商支持 Trixie 后,才重新启用第三方存储库。然后检查软件是否需要单独的升级或迁移步骤。
If something goes wrong If apt update fails, inspect both .list and .sources files for typos, mixed Debian releases, or unsupported vendor entries. Don’t proceed with a broken repository state. If an upgrade was interrupted, first establish whether APT or dpkg is still running. Once no package manager process is active, these commands can help recover an interrupted configuration or dependency operation: sudo dpkg —configure -a sudo apt —fix-broken install Review their proposed changes; stop if they suggest removals you did not expect. Don’t delete package locks or force-remove unfamiliar packages as a shortcut. If the machine no longer boots or SSH is unreachable, use the provider console or recovery environment and follow your backup plan.
如果出现问题。如果 apt update 失败,请检查 .list 和 .sources 文件是否存在拼写错误、混合的 Debian 版本或不受支持的供应商条目。不要在存储库状态损坏的情况下继续操作。如果升级中断,首先确定 APT 或 dpkg 是否仍在运行。一旦没有活动的软件包管理器进程,这些命令可以帮助恢复中断的配置或依赖操作:sudo dpkg —configure -a、sudo apt —fix-broken install。审查它们提出的更改;如果它们建议删除你未预料到的内容,请停止。不要删除软件包锁或强制删除不熟悉的软件包作为捷径。如果机器无法启动或 SSH 无法访问,请使用提供商控制台或恢复环境,并遵循你的备份计划。