Debian 13 升级指南
准备工作
首先请阅读 官方发布说明。
如果您的系统是 “标准 Debian 系统加上少量第三方软件源”,那么本指南可以帮助您从 Debian 12 “bookworm” 平滑升级到 Debian 13 “trixie”。我们将使用 find 命令处理第三方软件源。
注意:仅支持从 Debian 12 升级到 Debian 13。如果您仍在使用 Debian 11,请先 升级到Debian 12,然后再升级到 Debian 13。
本指南仅针对操作系统本身。各类应用程序可能需要额外操作步骤,请提前做好规划。
# 检查磁盘空间
df -h
建议至少保留 5GiB 空闲空间。可以使用 sudo apt clean 和 sudo apt autoremove 命令释放部分空间。
在仅安装 docker 的服务器上,1GiB 空闲空间也足够完成升级,但仍建议预留更多空间。
升级步骤
1. 识别需要更新的第三方软件源
ls /etc/apt/sources.list.d
2. 更新当前系统
apt update && apt dist-upgrade --autoremove -y
如果更新包含新内核,请执行 reboot 重启系统,否则继续下一步。
3. 将软件源从 Bookworm 改为 Trixie
sed -i 's/bookworm/trixie/g' /etc/apt/sources.list
4. 更新所有第三方软件源
注意:这假设第三方源已提供 trixie 版本。 修改后运行
apt update确认,并处理不可用的软件源。
find /etc/apt/sources.list.d -type f -exec sed -i 's/bookworm/trixie/g' {} \;
5. (可选) 启动 Screen 会话
为防止 SSH 断开导致升级中断,可以在 screen 中运行:
apt install -y screen && screen
6. 执行系统升级
在以下过程中,当提示是否重启服务时选择 ” 是 “,并在配置文件冲突时选择保留现有配置。
apt update && apt dist-upgrade --autoremove -y
使用 for 循环
for i in {update,upgrade,dist-upgrade,autoremove,autoclean};do apt $i -y;done
7. 最后重启系统
reboot
高级选项
现代化软件源格式
(可选但推荐) 将 sources.list 转换为 deb822 格式,这将创建:
/etc/apt/sources.list.d/debian.sources/etc/apt/sources.list.d/debian-backports.sources
sudo apt modernize-sources
注意:某些第三方镜像的 trixie-backports 可能缺少
Signed-By字段,可手动在/etc/apt/sources.list.d/debian-backports.sources中添加:Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
新增 DEB822 格式官方源:
tee /etc/apt/sources.list.d/debian.sources <<-'EOF'
Types: deb
URIs: https://deb.debian.org/debian
Suites: trixie trixie-updates
Components: main non-free-firmware
Enabled: yes
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
Types: deb
URIs: https://security.debian.org/debian-security
Suites: trixie-security
Components: main non-free-firmware
Enabled: yes
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF
新增 DEB822 格式中科大源:
tee /etc/apt/sources.list.d/debian.sources <<-'EOF'
Types: deb
URIs: http://mirrors.ustc.edu.cn/debian
Suites: trixie trixie-updates
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
Types: deb
URIs: http://mirrors.ustc.edu.cn/debian-security
Suites: trixie-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF