This article will guide you on how to upgrade Debian 11 Bullseye to Debian 12 Bookworm.

Preparation

Unless you are a physical server, and a KVM-built VPS and cloud host that has not used an oddly customized or modified kernel, there is a chance that upgrading to a major kernel update will cause Grub to fail to load, so remember to back up your important data!

OpenVZ 6 and LXC architecture VPS cannot be upgraded because they do not have their own independent kernel.

Again, always back up your important data!

The following operations need to be done under the root user, please use sudo -i or su root to switch to the root user

Update your system

First you need to update your current system.

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

If the kernel has been updated, you can reboot to allow the latest kernel to take effect, or you can simply perform an upgrade.

Upgrade your system

First update the apt source, replacing bullseye with bookworm.

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

For Debian 12 onwards, all packaged non-free firmware binaries (non-free) that Debian can distribute, such as certain drivers, have been moved to a new component in the Debian Archive, called non-free-firmware. If you are upgrading from an older version of Debian and need these firmware binaries, you should update the /etc/apt/sources.list on your system to use this new component (source):

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

The default system apt source file /etc/apt/sources.list should look something like this:

1
2
3
4
5
6
7
8
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb-src 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-src 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
deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware

Then we execute the update system again.

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

The update process will prompt whether some software needs to be restarted automatically, select Yes, and whether the configuration file of some software needs to be updated, select according to your situation.

In the apt-listchanges: News screen you can press q to exit.

During the update process you will be prompted if some software needs to be restarted automatically, select Yes to do so, and if the configuration file of some software needs to be updated, you can choose whether to update it according to your situation. Press enter to be considered as using the old configuration file.

In the apt-listchanges: News screen you can press q to exit.

apt-listchanges: News

Whether to restart the service automatically.

Whether to restart the service automatically.

Whether to update the OpenSSH configuration file.

Whether to update the OpenSSH configuration file.

Note that some software updates may update the systemd service configuration, in which case we can execute systemctl daemon-reload to reload the configuration.

If you encounter the following error while upgrading.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
Setting up dbus-daemon (1.14.6-1) ...
UUID file '/var/lib/dbus/machine-id' should contain a hex string of length 32, not length 0, with no other text
dpkg: error processing package dbus-daemon (--configure):
 installed dbus-daemon package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of dbus:
 dbus depends on dbus-daemon (= 1.14.6-1); however:
  Package dbus-daemon is not configured yet.

dpkg: error processing package dbus (--configure):
 dependency problems - leaving unconfigured
Processing triggers for libc-bin (2.36-9) ...
Errors were encountered while processing:
 dbus-daemon
 dbus
E: Sub-process /usr/bin/dpkg returned an error code (1)

Delete the empty file /var/lib/dbus/machine-id and re-execute the command, it will be generated automatically when upgrading dbus.

1
rm -rf /var/lib/dbus/machine-id

Remove unnecessary software and dependencies after updating:

1
2
apt autoclean
apt autoremove -y

We then use the reboot command to reboot the system. After waiting patiently, check for the latest system version.

1
2
root@debian ~ # cat /etc/debian_version 
12.0
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-9-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.27-1 (2023-05-08) x86_64 GNU/Linux