Product SiteDocumentation Site

6.7. 升级至下个稳定发行版

Debian 知名的功能之一是可升级至下个稳定版:dist-upgrade — 知名的句子 — 相当促进 Debian 的名声。除了极少的例外,升级电脑系统只需几分钟的时间,或十来分钟,依照从软件包保存库下载的速度而定.

6.7.1. 推荐的程序

Debian 各稳定版之间存在相当的差异,升级前应仔细阅读发布说明。
In this section, we will focus on upgrading a Bullseye system to Bookworm. This is a major operation on a system; as such, it is never 100% risk-free, and should not be attempted before all important data has been backed up.
Another good habit which makes the upgrade easier (and shorter) is to tidy your installed packages and keep only the ones that are really needed. Helpful tools to do that include aptitude, deborphan, debfoster, and apt-show-versions (see 第 6.2.7 节 “自动追踪已安装的软件包”). For example, you can use the following command, and then use aptitude's interactive mode to double check and fine-tune the scheduled removals:
# deborphan | xargs aptitude --schedule-only remove
Now for the upgrading itself. First, you need to change the /etc/apt/sources.list file to tell APT to get its packages from Bookworm instead of Bullseye. If the file only contains references to Stable rather than explicit codenames, the change isn't even required, since Stable always refers to the latest released version of Debian. In both cases, the database of available packages must be refreshed with the apt update command or the refresh button in synaptic (第 6.2.1 节 “初始化”).
Once these new package sources are registered, you should first do a minimal upgrade with apt upgrade et al. as described in 第 6.2.3 节 “系统升级”. By doing the upgrade in two steps, we ease the job of the package management tools and often ensure that we have the latest versions of those, which might have accumulated bugfixes and improvements required to complete the full distribution upgrade.
Once this first upgrade is done, it is time to handle the upgrade itself, either with apt full-upgrade, aptitude, or synaptic (第 6.7 节 “升级至下个稳定发行版”). You should carefully check the suggested actions before applying them: you might want to add suggested packages or deselect packages which are only recommended and known not to be useful. In any case, the frontend should come up with a scenario ending in a coherent and up-to-date Bookworm system. Then, all you need is to do is wait while the required packages are downloaded, answer the debconf questions and possibly those about locally modified configuration files, and sit back while APT does its magic.

6.7.2. 处理升级后的问题

尽管 Debian 管理者已经尽力做好份内的工作,主系统的升级仍可能不如想像中顺利。软件的新版本可能无法与旧版本兼容 (例如,可能改变缺省行为或数据格式)。同时,尽管在 Debian 发布前做了详尽的测试,还是有若干漏网的错误。
要解决这些问题,可以先安装 apt-listchanges 软件包,在软件包升级前先显示可能问题。由软件包维护者编辑的这些信息且置于 /usr/share/doc/软件包名/NEWS.Debian 文件名内,供用户参考。阅读这些文件 (可能经由 apt-listchanges) 应有助于规避意外。
You might sometimes find that the new version of a software doesn't work at all. This generally happens if the application isn't particularly popular and hasn't been tested enough; a last-minute update can also introduce regressions which are only found after the stable release. In both cases, the first thing to do is to have a look at the bug tracking system at https://bugs.debian.org/package, and check whether the problem has already been reported. If this is case, it will be also listed before the upgrade begins if you have apt-listbugs installed. If it hasn't, you should report it yourself with reportbug. If it is already known, the bug report and the associated messages are usually an excellent source of information related to the bug:
  • 有时已有补丁,并且列在错误报告内;可以本地重新编译修补破碎的软件包 (见 第 15.1 节 “从源码重新构建安装包”);
  • 否则,用户可能找到另外的解决方法且在报告内分享;
  • 再不然,维护者可能已准备并公开修订软件包。
很严重的错误,将有特别的软件包供稳定版使用。在这种情况下,修订后的软件包位于 Debian 镜像站的 proposed-updates 区域 (见 第 6.1.2.3 节 “计划更新”)。对应的条目暂时加在 sources.list 文件内,可用 aptaptitude 命令安装升级软件包。
修订软件包尚未被稳定版管理者认可时,就不会出现在此区块。用户必须自己动手认可它。虽然列在此的软件包尚未可得,但至少已知在审查中。

6.7.3. 升级后的清理

APT通常保证干净升级,下载新的和更新的依赖项,或移除冲突软件包。但是,即使是如此出色的工具,也不能涵盖用户和管理员在升级后将面对的所有任务,需要人工决策。

6.7.3.1. 从Debian存档中删除包

Sometimes the Debian ftpmasters remove packages from the Debian archive, because they contain release critical bugs, were abandoned by their upstream author or their package maintainer, or simply reached their end of life. In this case, a newer Debian release does not ship the package anymore. To find all packages, which do not have a package source, use the apt-show-versions command:
$ apt-show-versions | grep "No available version"
通过 aptitude search ~o 可以存档类似的结果。如果关键包不再需要,应该从系统中删除,因为不再有关键和安全相关问题的更新。

6.7.3.2. 虚拟和过渡软件包

有时,软件包可能需要有一个新的名称。这是通常旧的软件包保留为(几乎)空的包,依赖新的软件包,并在 /usr/share/doc/package/ 中安装强制文件。这些包称为"虚拟"或"过渡"软件包。如果软件包维护者将此包的区域更改为 oldlibs,则如 aptitudedeboprhandebfoster等工具 (见侧栏 其他 deborphandebfoster)可以识别并建议删除这些包。
不幸的是,目前没有万无一失的方法确保上述工具自动删除或识别这些软件包。要检查系统是否仍安装有这些软件包的方法,是查看已安装软件包的描述并检查结果。应小心不要安排结果自动删除,因为此方法会导致误报:
$ dpkg -l | grep ^ii | grep -i -E "(transition|dummy)"
因为新软件包是作为过渡软件包的依赖项安装的,通常会标记为自动安装,在尝试从系统删除过渡软件包时可能安排删除。这时可以使用侧栏 提示 同时进行卸载和安装第 6.2.7 节 “自动追踪已安装的软件包” 描述的方法选择性删除过渡包。

6.7.3.3. 旧的或不再使用的配置文件

If the upgrade was successful, there might be some configuration file cruft, either from dpkg (see 第 5.2.3 节 “Checksums, List of Configuration Files, et al.”), ucf or from removed packages. The latter can be purged by using apt autoremove --purge. The configuration files that were handled by dpkg or ucf during the upgrade process have left some counterparts with a dedicated suffix, e.g. .dpkg-dist, .dpkg-old, .ucf-old. Using the find or locate command can help to track them down. If they are no longer of any use, they can be deleted.
Be aware that a purge also removes the data created with a particular package (e.g. database files, docker volumes and containers, etc.). There should always be backups in place in case data gets removed accidentally.

6.7.3.4. 不属于任何包的文件

Debian 原则强制软件包在删除时不能留下文件。违反原则会是一个严重错误,您很少会遇到。如果遇到此问题,请报告;如果您好奇,可以使用 cruftcruft-ng 软件包检查系统是否由文件不属于任何软件包。