Debian 11 升级 Debian 12

准备工作

最近买了台vps,debian系统最高只有11,而我go编译出来的二进制不能直接运行,需要升级到12

所以我网上查询了升级的方法,并成功升级

更新系统

1
2
3
4
5
apt update
apt upgrade -y
apt dist-upgrade -y
apt autoclean
apt autoremove -y

如果内核更新了,可以重启让最新的内核生效,也可以直接进行升级。

升级系统

首先更新 apt 源,替换 bullseyebookworm

1
2
sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list
sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list.d/*.list

对于 Debian 12 以后的版本,所有 Debian 可以分发的打包的非自由固件二进制文件 (non-free),比如某些驱动,都被转移到 Debian Archive 中的一个新组件,称为非自由固件 (non-free-firmware)。如果您从旧版的 Debian 升级,并且需要这些固件二进制文件,您应该更新您系统上的 /etc/apt/sources.list,以使用这个新组件 (来源):

1
sed -i 's/non-free/non-free non-free-firmware/g' /etc/apt/sources.list

默认的系统 apt 源文件 /etc/apt/sources.list 应该是类似这样的

1
2
3
4
5
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware

deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware

deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware

大部分 Debian 的软件源配置文件使用传统的 One-Line-Style,路径为 /etc/apt/sources.list;但是对于容器镜像,从 Debian 12 开始,其软件源配置文件变更为 DEB822 格式,路径为 /etc/apt/sources.list.d/debian.sources参考

1
2
3
4
5
6
7
8
9
10
11
Types: deb
URIs: https://deb.debian.org/debian
Suites: bookworm bookworm-updates bookworm-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb
URIs: http://security.debian.org/debian-security
Suites: bookworm-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

国内服务器可以替换 deb.debian.orgsecurity.debian.orgmirrors.tuna.tsinghua.edu.cn

然后我们再次执行更新系统:

1
2
3
apt update
apt upgrade -y
apt dist-upgrade -y

更新后

更新后删除不必要的软件和依赖

1
2
apt autoclean
apt autoremove -y

然后我们使用 reboot 命令重启系统,耐心等待后,查看最新的系统版本

1
2
root@debian ~ # cat /etc/debian_version 
12.5
1
2
3
4
5
6
root@debian ~ # lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
1
2
root@debian ~ # uname -a
Linux debian 6.1.0-21-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 (2024-05-03) x86_64 GNU/Linux

这时我们就已经更新到了最新的 Debian 12 Bookworm 和内核了。

Debian 11 Bullseye 升级 Debian 12 Bookworm