Uncategorized

How to upgrade Debian 7 (wheezy) to 10 (buster) safely

This tutorial explains the procedure to upgrade Debian 7 (wheezy) to Debian 10 (buster) in a few simple steps.

Step 1: Backup all critical data

Before you start with the upgrade, backup all critical data. That’s especially the config data in the /etc directory and the user data in /home. When you run a server then you should include the databases (MySQL, PostgreSQL, etc), web and email data in the backup as well. The backup should be stored on an external hard disk, on an external server e.g. by FTP or on a cloud drive. Here are a few examples of how to create backups with tar.

Backup the configuration and data

Configuration files in the /etc directory.

tar -pczf etc.tar.gz /etc

Backup of the /var/www website directory.

tar -pczf www.tar.gz /var/www

Backup of the /home directories.

tar -pczf home.tar.gz /home

Backup of the /usr/local/directadmin directory.

tar -pczf direct_admin.tar.gz /usr/local/directadmin

Backup MySQL databases.

mysqldump --defaults-file=/etc/mysql/debian.cnf -cCeQ --hex-blob --quote-names --routines --events --triggers --all-databases -r all_databases.sql

Then move the tar.gz and .sql files for safe storage on a backup drive.

Step 2: Upgrade Debian 7 (wheezy) to 8 (jessie)

We will install all available wheezy updates first before we upgrade to jessie. After a Debian version has reached EOL (end of life), its repositories go to the Debian archive. Therefore we can use this archive to get packages for our distribution. The syntax for our /etc/apt/sources.list is as follows:

deb http://ftp.debian.org/debian/ wheezy main
deb-src http://ftp.debian.org/debian/ wheezy main

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

deb http://security.debian.org/ wheezy/updates main
deb-src http://security.debian.org/ wheezy/updates main

# wheezy-updates, previously known as 'volatile'
deb http://ftp.debian.org/debian/ wheezy-updates main
deb-src http://ftp.debian.org/debian/ wheezy-updates main

Our file /etc/apt/sources.list example after changes:

deb http://archive.debian.org/debian/ wheezy main
deb-src http://archive.debian.org/debian/ wheezy main

deb http://archive.debian.org/debian-security wheezy/updates main

deb http://archive.debian.org/ wheezy/updates main
deb-src http://archive.debian.org/ wheezy/updates main

# wheezy-updates, previously known as 'volatile'
deb http://archive.debian.org/debian/ wheezy-updates main
deb-src http://archive.debian.org/debian/ wheezy-updates main

On some systems, the package source is defined as “stable” in the sources.list file instead of “wheezy” or “jessie”. To avoid an accidental early upgrade to jessie, please check the sources.list now and ensure that it contains “wheezy” and not “stable” as source:

Use a command line editor like nano or vi to open /etc/apt/sources.list, the lines should be similar to the ones below:

nano /etc/apt/sources.list
deb http://archive.debian.org/debian/ wheezy main
deb-src http://archive.debian.org/debian/ wheezy main

deb http://archive.debian.org/debian-security wheezy/updates main

deb http://archive.debian.org/ wheezy/updates main
deb-src http://archive.debian.org/ wheezy/updates main

# wheezy-updates, previously known as 'volatile'
deb http://archive.debian.org/debian/ wheezy-updates main
deb-src http://archive.debian.org/debian/ wheezy-updates main

Update the packages for Debian 7
The following commands will install all pending wheezy updates. This ensures that your system is in a good shape for the update to jessie.

apt-get update

Ready for the first upgrade:

apt-get upgrade

Follow this with:

apt-get dist-upgrade

Check the package state to ensure that no packages are on hold or in half installed state
This test is important, we will check the package state to ensure that no packages are on hold or in half installed state. Your system and apt database must be in a good shape before we proceed with the dist upgrade. If there are any broken or “on hold” packages, then fix these issues before the upgrade.

Check that no packages are on hold by querying the package database with the dpkg command:

dpkg --audit
dpkg --get-selections | grep hold

When both commands did not return any packages, then proceed with the upgrade.

Update the sources.list for Debian 8
Edit the /etc/apt/sources.list file again:

nano /etc/apt/sources.list

and replace its content with the following lines:

deb http://ftp.debian.org/debian/ jessie main
deb-src http://ftp.debian.org/debian/ jessie main

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

deb http://security.debian.org/ jessie/updates main
deb-src http://security.debian.org/ jessie/updates main

# jessie-updates, previously known as 'volatile'
deb http://ftp.debian.org/debian/ jessie-updates main
deb-src http://ftp.debian.org/debian/ jessie-updates main

Get public key:

gpg --keyserver keys.gnupg.net --recv-key AA8E81B4331F7F50
gpg -a --export AA8E81B4331F7F50 | apt-key add -

Save the file and run the following command to update the sources database:

apt-get update

Check if packages are upgradable
We can test with apt command if the installed packages are upgradable. Run this command to perform the test:

apt-get -u upgrade --assume-no

From the apt-get man page:

-u
--show-upgraded  Show upgraded packages; Print out a list of all packages that are to be upgraded. Configuration Item: APT::Get::Show-Upgraded.
--assume-no  Automatic "no" to all prompts. <== To prevent it from starting to install

Debian 7 (wheezy) to Debian 8 (jessie) Update in two steps
It is recommended to do the upgrade in two steps, first run “apt-get upgrade” to install the base packages and then run “apt-get dist-upgrade” to do the actual distribution upgrade,

Start with the update by running this command:

apt-get upgrade

Next, we will do the distribution upgrade by running:

apt-get dist-upgrade

A reboot is required to finish the upgrade and load the new kernel:

reboot

Check the update
To check which Debian version is currently installed on the system, take a look at the file /etc/os-release.

cat /etc/os-release

The result on a Debian jessie system is:

PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Step 3: Upgrade Debian 8 (jessie) to 9 (stretch)

We will install all available jessie updates first before we upgrade to stretch.
On some systems, the package source is defined as “stable” in the sources.list file instead of “jessie” or “stretch”. To avoid an accidental early upgrade to stretch, please check the sources.list now and ensure that it contains “jessie” and not “stable” as source:

Use a command line editor like nano or vi to open /etc/apt/sources.list, the lines should be similar to the ones below:

nano /etc/apt/sources.list
deb http://ftp.debian.org/debian/ jessie main
deb-src http://ftp.debian.org/debian/ jessie main

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

deb http://security.debian.org/ jessie/updates main
deb-src http://security.debian.org/ jessie/updates main

# jessie-updates, previously known as 'volatile'
deb http://ftp.debian.org/debian/ jessie-updates main
deb-src http://ftp.debian.org/debian/ jessie-updates main

Update the packages for Debian 8
The following commands will install all pending jessie updates. This ensures that your system is in a good shape for the update to stretch.

apt-get update

Ready for the first upgrade:

apt-get upgrade

Follow this with:

apt-get dist-upgrade

Check the package state to ensure that no packages are on hold or in half installed state
This test is important, we will check the package state to ensure that no packages are on hold or in half installed state. Your system and apt database must be in a good shape before we proceed with the dist upgrade. If there are any broken or “on hold” packages, then fix these issues before the upgrade.

Check that no packages are on hold by querying the package database with the dpkg command:

dpkg --audit
dpkg --get-selections | grep hold

When both commands did not return any packages, then proceed with the upgrade.

Update the sources.list for Debian 9
Edit the /etc/apt/sources.list file again:

nano /etc/apt/sources.list

and replace its content with the following lines:

deb http://ftp.debian.org/debian/ stretch main
deb-src http://ftp.debian.org/debian/ stretch main

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

deb http://security.debian.org/ stretch/updates main
deb-src http://security.debian.org/ stretch/updates main

# stretch-updates, previously known as 'volatile'
deb http://ftp.debian.org/debian/ stretch-updates main
deb-src http://ftp.debian.org/debian/ stretch-updates main

Save the file and run the following command to update the sources database:

apt-get update

Check if packages are upgradable
We can test with apt command if the installed packages are upgradable. Run this command to perform the test:

apt list --upgradable

Debian 8 (jessie) to Debian 9 (stretch) Update in two steps
It is recommended to do the upgrade in two steps, first run “apt-get upgrade” to install the base packages and then run “apt-get dist-upgrade” to do the actual distribution upgrade,

Start with the update by running this command:

apt-get upgrade

Next, we will do the distribution upgrade by running:

apt-get dist-upgrade

A reboot is required to finish the upgrade and load the new kernel:

reboot

Check the update
To check which Debian version is currently installed on the system, take a look at the file /etc/os-release.

cat /etc/os-release

The result on a Debian stretch system is:

PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Step 4: Upgrade Debian 9 (stretch) to 10 (buster)

We will install all available stretch updates first before we upgrade to buster.
On some systems, the package source is defined as “stable” in the sources.list file instead of “stretch” or “buster”. To avoid an accidental early upgrade to buster, please check the sources.list now and ensure that it contains “stretch” and not “stable” as source:

Use a command line editor like nano or vi to open /etc/apt/sources.list, the lines should be similar to the ones below:

nano /etc/apt/sources.list
deb http://ftp.debian.org/debian/ stretch main
deb-src http://ftp.debian.org/debian/ stretch main

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

deb http://security.debian.org/ stretch/updates main
deb-src http://security.debian.org/ stretch/updates main

# stretch-updates, previously known as 'volatile'
deb http://ftp.debian.org/debian/ stretch-updates main
deb-src http://ftp.debian.org/debian/ stretch-updates main

Update the packages for Debian 9
The following commands will install all pending stretch updates. This ensures that your system is in a good shape for the update to buster.

apt-get update

Ready for the first upgrade:

apt-get upgrade

Follow this with:

apt-get dist-upgrade

Check the package state to ensure that no packages are on hold or in half installed state
This test is important, we will check the package state to ensure that no packages are on hold or in half installed state. Your system and apt database must be in a good shape before we proceed with the dist upgrade. If there are any broken or “on hold” packages, then fix these issues before the upgrade.

Check that no packages are on hold by querying the package database with the dpkg command:

dpkg --audit
dpkg --get-selections | grep hold

When both commands did not return any packages, then proceed with the upgrade.

Update the sources.list for Debian 10
Edit the /etc/apt/sources.list file again:

nano /etc/apt/sources.list

and replace its content with the following lines:

deb http://ftp.debian.org/debian/ buster main
deb-src http://ftp.debian.org/debian/ buster main

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

deb http://security.debian.org/ buster/updates main
deb-src http://security.debian.org/ buster/updates main

# buster-updates, previously known as 'volatile'
deb http://ftp.debian.org/debian/ buster-updates main
deb-src http://ftp.debian.org/debian/ buster-updates main

Save the file and run the following command to update the sources database:

apt-get update

Check if packages are upgradable
We can test with apt command if the installed packages are upgradable. Run this command to perform the test:

apt list --upgradable

Debian 9 (stretch) to Debian 10 (buster) Update in two steps
It is recommended to do the upgrade in two steps, first run “apt-get upgrade” to install the base packages and then run “apt-get dist-upgrade” to do the actual distribution upgrade,

Start with the update by running this command:

apt-get upgrade

Next, we will do the distribution upgrade by running:

apt-get dist-upgrade

A reboot is required to finish the upgrade and load the new kernel:

reboot

Check the update
To check which Debian version is currently installed on the system, take a look at the file /etc/os-release.

cat /etc/os-release

The result on a Debian buster system is:

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"