How to Upgrade Debian 8 (Jessie) to 9 (Stretch) safely

This tutorial explains the procedure to upgrade Debian 8 to 9 in a few simple steps.

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

For ISPConfig 3 users: Backup of your email server files.

tar -pczf vmail.tar.gz /var/vmail

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.

Check the apt sources.list file

We will install all available Jessie updates first before we upgrade to Jessie. 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://httpredir.debian.org/debian jessie main contrib non-free
deb http://httpredir.debian.org/debian jessie-updates main contrib non-free
deb http://security.debian.org jessie/updates main contrib non-free

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://httpredir.debian.org/debian stretch main contrib non-free
deb http://httpredir.debian.org/debian stretch-updates main contrib non-free
deb http://security.debian.org stretch/updates main contrib non-free

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 to 9 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:

Debian updated to version 9

Share this page:

Suggested articles

25 Comment(s)

Add comment

Comments

By: diablo666 at: 2018-01-22 14:52:02

Works with ispconfig installed right?

Something to do for that?

By: Ben at: 2018-01-23 01:37:24

Some optional cleanup steps, before editing sources...

apt-get --purge remove `deborphan`  (purge some unneeded packages - repeat until nothing is removed )

apt-get --purge autoremove  ( purge auto-installed packages)

aptitude search "~o"  (to find obsolete packages, which might be worth removing)

By: Tomas at: 2018-01-23 10:27:16

Will this upgrade the kernel as well? It looks like it does not.

By: till at: 2018-01-23 11:43:04

Yes, a dist upgrade will upgrade the Linux Kernel,

By: Grant at: 2018-01-23 16:00:20

I would add one step. After doing the update, but before the upgrade do "apt-get dist-upgrade -d"  Having everything downloaded and local before you start can be a significant benefit, not dealing with network issues during an upgrade.

By: peter3332 at: 2018-02-13 16:54:53

Will this work over 2 versions from debian 7 to 9  or i shoud do 7 -> 8 -> 9 ?

By: till at: 2018-02-13 21:59:41

I won't skip a release in the upgrade process. But it might work, just haven't tested that.

By: SamTzu at: 2018-03-16 13:18:14

I would remove fail2ban before upgrading. It usually brakes during upgrade.

By: pattone at: 2018-06-14 12:50:59

What is better.... "apt-get update && apt-get upgrade"  or "apt update && apt upgrade" ??

By: toto1988 at: 2018-07-12 08:41:31

Thank you! :)

By: simon at: 2018-08-03 20:13:49

work ok 

Thank

By: Z3r0h0ur at: 2018-09-18 14:38:33

Postfix is not working after upgrade, as it's upgrading from 2.x to 3.x . Couldn't find a fix for that yet (

By: c3n at: 2018-12-22 13:09:37

The postfix issue is created because of spamd and spamassassin demon. Try to stop those services, then restart postfix service -- everything should be fine. If not, check hostname, hosts, mailname for errors. On most of my servers i had to remove spamd and spamassassin and everything is working fine.

By: Jos at: 2019-03-04 13:43:14

All went well with the above help but....IP address doesn't work anymore, both sites now offline! ISConfig gives empty screen. Please help.Jos..

By: till at: 2019-03-04 13:57:13

Run an ISPConfig update and choose yes when the updater asks you to reconfigure services.

By: Spacestar54 at: 2019-03-04 15:07:35

Still can't reply. Is this the update line: ispconfig_update.sh Doesn't help. Jos...

By: Jos at: 2019-03-04 14:42:40

Can't reply. But update did not solved the problem.

By: till at: 2019-03-04 15:13:24

I have no Idea why you write into each reply while sending the reply. But back to your topic, if you need further help, then please make a thread in the ispconfig forum here at howtoforge with the exact errors that you get in the log files of the failed services.

By: David at: 2019-03-27 08:16:28

I did the upgrade as recommanded.

After an initial panic (maria-db wouldn't work), I rebooted the server it came back fine.

I had to uninstall and reinstall fail2ban to make it work (with new config).

I only found one minor problem:In "Server Load" the "Users Online" stays to 0 even when I'm connected with SSH

By: Francis Rodrigues at: 2019-04-12 03:53:49

Por que usar "main contrib non-free" e não o default "main"?

By: HitoDev at: 2019-06-11 10:11:08

Hello,

I followed this guide.

During Debian 8 upgrade, at the end, I got:

*****************************

Preparing to unpack .../mariadb-client_10.1.38-0+deb9u1_all.deb ...Unpacking mariadb-client (10.1.38-0+deb9u1) over (10.0.30-0+deb8u2) ...Preparing to unpack .../mariadb-server_10.1.38-0+deb9u1_all.deb ...Unpacking mariadb-server (10.1.38-0+deb9u1) over (10.0.30-0+deb8u2) ...(Reading database ... 64480 files and directories currently installed.)Removing mariadb-server-10.0 (10.0.30-0+deb8u2) ...6623There is a MySQL server running, but we failed in our attempts to stop it.Stop it yourself and try again!dpkg: error processing package mariadb-server-10.0 (--remove): subprocess installed pre-removal script returned error exit status 1dpkg: mariadb-client-10.0: dependency problems, but removing anyway as you requested: mariadb-server-10.0 depends on mariadb-client-10.0 (>= 10.0.30-0+deb8u2); however:  Package mariadb-client-10.0 is to be removed. roundcube-mysql depends on mariadb-client | mysql-client | virtual-mysql-client; however:  Package mariadb-client is not configured yet.  Package mysql-client is not installed.  Package virtual-mysql-client is not installed.  Package mariadb-client-10.0 which provides virtual-mysql-client is to be removed.Removing mariadb-client-10.0 (10.0.30-0+deb8u2) ...Removing mariadb-client-core-10.0 (10.0.30-0+deb8u2) ...Processing triggers for man-db (2.7.6.1-2) ...Errors were encountered while processing: mariadb-server-10.0E: Sub-process /usr/bin/dpkg returned an error code (1)You have new mail in /var/mail/root

*****************************

This is a Debian 8 / ispConfig server.

what am I supposed to do?

Nees I stop 'manualy' mysql and run again ?

apt-get dist-upgrade

 

 

By: AMPSYS at: 2019-06-26 21:03:06

Didn't see a response to diablo666's question below:  Is this safe with ISPCONFIG installed?

 

I have a multiserver setup (Web, NS1, NS2, and SQL) that are all running 8 @ 3.1.13p1 that I'd like to upgrade to 9.

 

Thanks.

By: till at: 2019-06-27 05:33:12

Dist upgrades are never 100% save as you replace basically all software on your servers, no matter which instructions you use, so always do a backup first. There is always something that can go wrong. Thus said, I've updated several ISPConfig servers using this procedure successfully. First follow this guide, and then do an ispconfig update with reconfigure services = yes on the system to adapt the config files.

By: AMPSYS at: 2019-06-27 16:55:29

Tried this and it broke DNS on my ISPCONFIG 3.1.13p1 multi-server setup.  Fortunately, I took a snapshot prior and was able to revert back rather quickly.

By: Ammad at: 2019-07-08 08:50:52

Is it possible, upgrade from Debian 8 directly to Debian 10? How safe is it?