How to upgrade Debian 11 to Debian 12
Overview
Hi there fellow Linuxers! On today’s article we’re all about how to upgrade Debian, in this case, how to upgrade Debian 11 to Debian 12. For my upgrade scenario, I’ll be using a VM that runs Debian I use for one my Docker servers for my home lab and is in dire need for an upgrade.
Gathering info
To check your exact version you can use:
cat /etc/debian_version
To print specific info about your ditro type (-d is for detailed):
lsb_release -d
Or even more detailed info about your distro:
lsb_release -a
That’s more like it. Now that we have info about system version, we can proceed to next step.
Upgrading packages
CAUTION: Before we venture further take a word of advice and backup your system! Just in case if anything goes wrong. Backup is never a bad choice. Better safe than sorry!
Even though the steps seem to be straightforward, there’s allways a chance something may go wrong and i must give you a fair share of a warning and urge you to be careful with the commands and i implore you to backup all your data first or at least make sure that you’re not going to lose any data.
As a test bench, I allways go first with a VM or use an older, non important device to test out the process first.
Right at the beginning we better first check are there any packages in “on hold” status:
sudo apt-mark showhold
In my case there were none, but if any, install them first or discard them (sudo apt-mark unhold package_name
) just don’t let them unresolved because they could cause a problem during upgrade and we all know Murphy’s law “Anything that can go wrong will go wrong”. After dealing with third party packages, your next step is checking if current system if fully updated and fully upgraded:
sudo apt update
sudo apt upgrade
Just to be thorough also run this:
sudo apt full-upgrade
since this command will remove installed packages if necessary. Next steps include a bit of cleaning:
sudo apt --purge autoremove
sudo apt autoclean
Editing the sources list and running full upgrade
Now that we have system cleaned it’s time to edit sources list, where we’ll have to change codename (Debian 11 codename is bullseye and Debian 12 codename is bookworm). You can open /etc/apt/sources.list/
in an editor like Vim or Nano and change it manually but let’s be honest why would you do that when you can call almighty sed to your help:
sudo sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list
While we’re already here it’s best to modify sources list for hardware driver support.
sudo sed -i 's/non-free/non-free non-free-firmware/g' /etc/apt/sources.list
When we’re done with changes in sources list, time has come to run update again, which will update repo list:
sudo apt update
System is prepared for an ongoing upgrade.
CAUTION! Just a word of advice here. Full upgrade is a process during which you could experience losing packages you wish to keep, so Debian devs are recommending to split upgrade process in two phases:
- minimal upgrade
- full upgrade
Since I have 1622 packages I’ll do minimal upgrade first. Minimal system upgrade starts when you type in:
sudo apt upgrade --without-new-pkgs
When this phase is finished, you can advance to full upgrade:
sudo apt full-upgrade
During upgrade you’ll be prompted for restart during package upgrades:
You’ll be occasionally prompted to decide what to do and after a while upgrade process will be finished. Before restart, it’s better to clean unnecessary packages:
sudo apt --purge autoremove
sudo apt autoclean
The final step to finish this process is to restart your machine:
sudo systemctl reboot
And voila! Welcome to your upgraded system. You can use commands from beginning to check it:
cat /etc/debian_version
lsb_release -a
I don’t know have you noticed that kernel got updated too:
uname -mrs
Summary
Congrats! You successfully completed yet another Linux adventure and ended up having your Debian system upgraded. Win-Win situation! These upgrades allways feel satisfying when they go without a hitch and are completed on a first run.
Thank you again for taking time and I hope you found the post useful…