How to Upgrade from Debian 11 Bullseye to Debian 12 Bookworm

Introduction

Before we begin talking about how to upgrade from Debian 11 Bullseye to Debian 12 Bookworm, let's briefly understand – What is Debian 12?

Debian 11, also known as Debian GNU/Linux 11 "Bullseye", is the predecessor to Debian 12, the latest version of the Debian operating system. While Debian 11 offers stability and security, it has limitations. Its conservative update approach means that software packages may not be the latest version, which can be a disadvantage for users seeking the latest features or bug fixes.

In contrast, Debian 12, a free and open-source distribution, delivers stability, security, and versatility, making it popular among beginners and experienced users. With updated software, improved performance, and valuable features, Debian 12 is a compelling choice.

In this tutorial, you will upgrade from Debian 11 Bullseye to Debian 12 Bookworm. We will also address a few FAQs on how to upgrade from Debian 11 Bullseye to Debian 12 Bookworm.

Upgrade Debian 11 to Debian 12 Bookworm

The procedure is as follows:

  1. Backup the system.
  2. Update existing packages and reboot the Debian 11 system.
  3. Edit the file /etc/apt/sources.list using a text editor and replace each instance of bullseye with bookworm. Next, find the update line, replace keyword bullseye-updates with bookworm-updates. Finally, search the security line, replace keyword bullseye-security with bookworm-security.
  4. Update the packages index on Debian Linux, run:
    sudo apt upgrade
  5. Prepare for the operating system minimal system upgrade, run:
    sudo apt upgrade --without-new-pkgs
  6. Finally, update Debian 11 to Debian 12 Bookworm by running:
    sudo apt full-upgrade
  7. Restart the Linux system to enable Debian 12 Bookworm to boot.
  8. Make sure everything is operating as it should.

Let's examine each command in detail to safely update Debian 11 Bullseye to Debian 12 Bookworm in a bare metal or cloud environment.

Step 1. Backup Your System

💡
Completing the backup procedure is crucial in order to prevent data loss or installation issues. This is a basic lesson for sysadmins: the user is responsible for maintaining verified backups. If there is no backup, there is no way to hold the author or nixCraft responsible for any problems that occur.

It is crucial to backup all of your data and system configurations. Snapshots allow cloud-based virtual machines to be efficiently backed up and restored quickly. Rsnapshot is my go-to backup program because it's capable of backing up both local and remote servers. Use the lsb_release command on Linux to find the OS version. For example:

lsb_release -a
Output

No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 11 (bullseye)
Release:	11
Codename:	bullseye

Make a note of the Linux kernel version as well. Try using the command uname:

uname -mrs

The version of the Linux kernel:

Linux 5.10.0-23-amd64 x86_64

Additionally, use the cat command to record the Debian version:

cat /etc/debian_version
Output

11.7

Step 2. Update All Existing Installed Packages

You need to remove non-Debian packages in order to make the upgrade safer. For instance, third-party repositories are used to install non-Debian packages like Google Chrome or VirtualBox. Those might lead to an issue. Here's how to locate these pages:

sudo apt list '?narrow(?installed, ?not(?origin(Debian)))'
sudo apt-forktracer | sort

Luckily, I don't use VirtualBox, Google Chrome, or any other third-party Debian apps. Before updating, though, make sure you have a backup of your data if you use these apps. If the Bookworm release allows it, you can reinstall these packages after upgrading. Additionally, the upgrade process will encounter issues if any packages are in hold. Consequently, use the apt-mark command to list every package that is blocked from upgrades as follows:

sudo apt-mark showhold | more
# OR #
sudo dpkg --get-selections | grep 'hold$' | more

Next, using the following command, you have to delete or remove the host status for each listed package individually:

sudo apt-mark unhold package_name
## OR ##
echo 'package_name install' | sudo dpkg --set-selections

You must apply all security updates and pending upgrades to Debian 11 itself before you can upgrade to Debian version 12. Consequently, enter the apt-get or apt command as follows:

sudo apt update
sudo apt upgrade
sudo apt full-upgrade
sudo apt --purge autoremove
Output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  libssl1.1 openssl
2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,413 kB of archives.
After this operation, 4,096 B disk space will be freed.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.linode.com/debian-security bullseye-security/updates/main amd64 libssl1.1 amd64 1.1.1n-0+deb11u5 [1,559 kB]
Get:2 http://mirrors.linode.com/debian-security bullseye-security/updates/main amd64 openssl amd64 1.1.1n-0+deb11u5 [854 kB]
Fetched 2,413 kB in 0s (21.2 MB/s)
Reading changelogs... Done
Preconfiguring packages ...
(Reading database ... 30868 files and directories currently installed.)
Preparing to unpack .../libssl1.1_1.1.1n-0+deb11u5_amd64.deb ...
Unpacking libssl1.1:amd64 (1.1.1n-0+deb11u5) over (1.1.1n-0+deb11u4) ...
Setting up libssl1.1:amd64 (1.1.1n-0+deb11u5) ...
(Reading database ... 30868 files and directories currently installed.)
Preparing to unpack .../openssl_1.1.1n-0+deb11u5_amd64.deb ...
Unpacking openssl (1.1.1n-0+deb11u5) over (1.1.1n-0+deb11u4) ...
Setting up openssl (1.1.1n-0+deb11u5) ...
Processing triggers for man-db (2.9.4-2) ...
 
Processing triggers for libc-bin (2.31-13+deb11u6) ...##########################################

Using the "reboot" or "shutdown" commands, restart the Debian 11.x bullseye to apply the kernel and other updates. For example:

sudo systemctl reboot

Step 3. Update /etc/apt/sources.list file

The APT source-list files must be reconfigured before the upgrade can start. Using the commands: cat command or more command, you can see the current settings. The list of Debian 11 repository URLs will appear as a result.

sudo cat /etc/apt/sources.list
Output

deb http://deb.debian.org/debian bullseye main
deb http://deb.debian.org/debian bullseye-updates main
deb http://deb.debian.org/debian-security/ bullseye-security main

The term bullseye denotes that we are utilizing version 11, which is older. Therefore, we need to use a text editor like Vim or Nano to change all the references in this file from bullseye to bookworm. As an example:

sudo cp -v /etc/apt/sources.list /root/sources.list-bakup.11.bullseye
sudo vim /etc/apt/sources.list

From:

deb http://deb.debian.org/debian bullseye main
deb http://deb.debian.org/debian bullseye-updates main
deb http://deb.debian.org/debian-security/ bullseye-security main

To:

deb http://deb.debian.org/debian bookworm main
deb http://deb.debian.org/debian bookworm-updates main
deb http://deb.debian.org/debian-security/ bookworm-security main

Save and close the file. Additionally, you can locate and swap out bullseye with bookworm using the sed command as follows:

sudo sed -i'.bak' 's/bullseye/bookworm/g' /etc/apt/sources.list

A note about the non-free-firmware repo

It is advised to include the non-free firmware repository if you plan to use Debian 12 on a desktop or server that needs non-free firmware for hardware like WiFi, GPU, Sound, Nvida/AMD GPU, NIC, and more. The updated /etc/apt/sources.list file is shown below. Your hardware requires non-free firmware, as indicated by the orange color of the repository configuration. It is advised to add those repositories if you are unsure about your hardware.

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

Updating the package list

Lastly, execute the subsequent command to obtain updated apt repo data:

sudo apt update

Step 4. Minimal system upgrade

The following message was displayed by the system.

Output

1337 packages can be upgraded. Run 'apt list --upgradable' to see them.

Because of this, a two-step procedure is required to prevent discarding a significant portion of the packages you wish to keep. Consequently, to apply, first execute the following command:

sudo apt upgrade --without-new-pkgs

Please carefully follow the on-screen instructions to finish the upgrade. Throughout the process, you might be asked questions like "Would you like to restart the service?" and "Keep or erase configuration file options?" For example, the most recent changes:

To exit, please press q. You may also see more screens and dialogs:

Step 5. Upgrading Debian 11 to Debian 12

Complete upgrades are required, not just minimal ones, in order to update from Debian 11 to Debian 12. For the upgrade process to work, this step is essential. Enter the following command to accomplish this and make sure that all packages are installed to their most recent versions and that any possible dependencies are taken care of. As an example:

sudo apt full-upgrade

There may be additional prompts that suggest you to change the current configuration options or restart services. Make sure you give them a thorough review. For instance, you might be able to keep or update the OpenSSH configuration file:

And the updating process is now complete. Rebooting the Linux system is necessary to boot into Debian Linux 12 bookworm. Make sure the SSHD configuration file for the remote server is error-free before we restart the system:

sudo sshd -t

Rebooting the system can be done if there are no errors. On the other hand, it's crucial to address any errors before rebooting. To accomplish this, run:

sudo vim /etc/ssh/sshd_config

Verify again:

sudo sshd -t

After resolving any errors, restart it now:

sudo systemctl reboot
Output

Connection to 139.1xx.yyy.zz2 closed by remote host.
Connection to 139.1xx.yyy.zz2 closed.

To find out when your server returns online, try using the ping command:

ping -a server_IP_here
ping -a 139.1xx.yyy.zz2

Step 6. Verification

Done. It's time to verify the update. Style:

uname -mrs
Output

Linux 6.1.0-10-amd64 x86_64
lsb_release -a
Output

No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 12 (bookworm)
Release:	12
Codename:	bookworm

Verify the Debian major and minor versions as well:

cat /etc/debian_version
Output

12.1

Check out all of your apps and services after the update. Thus, use the tail, ss, grep, or egrep commands to confirm that all TCP/UDP ports are open and services are operating:

sudo ss -tulpn
sudo tail -f /var/log/mail.log
sudo tail -f /var/log/apache2/access_log
 
# look for errors if any
sudo grep 'error' /var/log/my_pyton_app/sales_app.log
sudo grep -E -i 'err|fail|warn|crit' /var/log/nginx/php_nixcraft_blog.log
 
# Check for service status
sudo systemctl status nginx.service
sudo systemctl status apache2.service
sudo systemctl status mariadb.service
 
# Use journalctl to query the contents of the systemd(1) journal
sudo journalctl
sudo journalctl -u sshd.service
💡
CAUTION! It is important to review any packages that are no longer required on your system, even though they are optional. If the following command is run without doing this, the system might crash.

Lastly, use the apt command or apt-get command to remove obsolete packages as follows:

sudo apt --purge autoremove

FAQs to Upgrade from Debian 11 Bullseye to Debian 12 Bookworm

Will I lose my data during the upgrade?

Generally, the upgrade process preserves user data. However, it's always recommended to have a backup of critical data before initiating any major system upgrade.

What happens to third-party software and repositories after the upgrade?

Third-party software and repositories may need to be reconfigured or updated after the upgrade. It's essential to check the compatibility of these components with the new Debian version.

Will my existing software packages be updated automatically during the upgrade?

Yes, during the upgrade process, your existing software packages will be updated to their respective versions compatible with Debian 12.

Are there any hardware requirements for upgrading to Debian 12?

Debian 12 generally maintains similar hardware requirements as Debian 11. It's advisable to check the official documentation for any changes or specific hardware considerations.

Can I roll back the upgrade if I encounter issues?

Rolling back to the previous version after an upgrade is not a straightforward process and is not officially supported. It is recommended to thoroughly test the upgrade in a non-production environment before proceeding.

How long does the upgrade process take?

The upgrade duration varies based on factors like system configuration and internet speed. It is advisable to allocate sufficient time for the upgrade process, as it may take a while to complete.

Will my system configurations and settings be preserved after the upgrade?

In most cases, system configurations and settings should be preserved during the upgrade. However, it's good practice to review and validate your system settings post-upgrade.

Conclusion

We hope this tutorial helped you understand how to upgrade from Debian 11 Bullseye to Debian 12 Bookworm.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.