Preface#
On June 10, 2023, Debian officially released its latest stable version 12 (code-named bookworm). As a Linux enthusiast, how can you not upgrade it as soon as possible.
Compared to Debian 11, Debian 12 contains a large number of updated packages (over 67% more than the previous version). Personally, I think it is still possible to upgrade, but it is better not to use it on the main machine in the early stage.
Preparation#
Unless you are using a physical server and a VPS or cloud host with the KVM architecture that has not been customized or modified with a strange kernel, there is a certain chance that upgrading the major version will cause Grub to fail to load. Remember to back up important data!
OpenVZ 6 and LXC architecture VPS cannot be upgraded because they do not have their own independent kernel.
I emphasize again, be sure to back up important data!
Command to check which version of Debian you are using.
cat /etc/debian_version
# Or
cat /etc/os-release
Update the system#
Before installation, please update the system first.
apt update
apt upgrade -y
apt dist-upgrade -y
apt autoclean
apt autoremove -y
If the kernel is updated, you can restart to make the latest kernel take effect, or you can directly upgrade.
Upgrade the system#
Manual upgrade#
First, update the apt source and replace bullseye with bookworm:
sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list
sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list.d/*.list
For versions after Debian 12, all non-free firmware binary files 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 binary files, you should update the /etc/apt/sources.list on your system to use this new component (source):
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 be similar to this:
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
For servers in China, you can replace deb.debian.org and security.debian.org with mirrors.tuna.tsinghua.edu.cn
Then we update the system again:
apt update
apt upgrade -y
apt dist-upgrade -y
During the update process, you will be prompted whether some software needs to be automatically restarted. Select Yes, and whether the configuration files of some software need to be updated. Choose according to your own situation. Press Enter by default to use the old configuration files. This usually occurs when updating software such as OpenSSH.
You can press q to exit the apt-listchanges: News interface:
Prompt whether to restart the service automatically:
Prompt whether to update the OpenSSH configuration file:
Note that some software updates may update the systemd service configuration. At this time, we can execute systemctl daemon-reload to reload the configuration.
If you encounter the following error during the upgrade:
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 then execute the command again. This file will be automatically generated when upgrading dbus.
rm -rf /var/lib/dbus/machine-id
After the update, remove unnecessary software and dependencies:
apt autoclean
apt autoremove -y
Then use the reboot command to restart the system. After waiting patiently, check the latest system version:
root@debian ~ # cat /etc/debian_version
12.0
root@debian ~ # lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
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
At this point, we have updated to the latest Debian 12 Bookworm and kernel.
Upgrade automatically using a script#
Script address: Github
Script command:
bash <(curl -sSL https://raw.githubusercontent.com/wikihost-opensource/linux-toolkit/main/system-upgrade/debian.sh)
If you are using Debian 10, you need to execute the script twice because the script only upgrades one version each time.
Upgrade Debian 9 to Debian 10
Upgrade Debian 10 to Debian 11
Upgrade Debian 11 to Debian 12
During the update process, you will be prompted whether some software needs to be automatically restarted. Select Yes, and whether the configuration files of some software need to be updated. Choose according to your own situation. Press Enter by default to use the old configuration files. This usually occurs when updating software such as OpenSSH. Please refer to the manual installation for details.
Finally#
I wish you all a happy time.
Thanks to the following articles:
The west wind is slanting on the lake, and the lotus flowers fall, leaving only red stamens