Upgrading Raspbian Jessie to Raspbian Stretch

This post describes how you can upgrade Raspbian Jessie, version 8, to Raspbian Stretch, version 9. Raspbian Stretch was recently released and while they recommend installing from fresh you are able to upgrade the versions. Here I follow the steps of upgrading the Raspberry Pi’s in my cluster including some of the common problems that may occur.

Preparing the Raspberry Pi’s before Upgrading

Before doing any kind of updates to your Raspberry Pi you should ensure all your important data is backed up. While upgrading the OS of a Raspberry Pi is relatively safe there is always a chance something might fail.

One of the ways you can fully backup your Raspberry Pi is by cloning the disk. This can be done by following my previous blog post explaining how to clone a Raspbian SD Card to another. While the previous blog post was intended to set up multiple Pi’s it can be used as a useful backup tool.

Instead of imaging the SD cards I am going to take a simple backup of the using scp. This follows the instructions on how to create a simple backup script I wrote previously.

Once the full backup of the machine has been completed I am ready to upgrade the Raspberry Pi.

Upgrading a Raspberry Pi to Raspbian Stretch

The first thing that needs to be done is update the sources files. This lists where the Raspberry Pi gets the details of package updates for. The following files need to be modified:

/etc/apt/sources.list
/etc/apt/sources.list.d/raspi.list

In both of the files we need to change every occurrence of the word jessie to stretch.  Both of these files require sudo rights to edit.

Once this has been done we can run the following two commands to update the Raspberry Pi to Raspbian Stretch.

sudo apt-get update
sudo apt-get -y dist-upgrade

Once this has finished running rebooting your machine will complete the upgrade.

Possible Errors during upgrade

During the upgrade process I encountered a couple errors over my various devices. Listed here are the errors and the fixes for them.

E: dpkg was interrupted

If this occurs, as in the full error below you need to run sudo dpkg --configure -a to correct the issue. The full error has been listed below.

E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

Once this has been run you can continue the upgrade process. The full commands to run to correct this and continue are reproduced below.

sudo dpkg --configure -a
sudo apt-get update
sudo apt-get -y dist-upgrade

APT had planned for dpkg to do more than it reported back

During the dist upgrade on one Raspberry Pi apt reported back the following error.

W: APT had planned for dpkg to do more than it reported back (5 vs 9).
 Affected packages: raspberrypi-ui-mods:armhf

Errors were encountered while processing:
 raspberrypi-ui-mods
E: Sub-process /usr/bin/dpkg returned an error code (1)

To fix this I rebooted the Raspberry Pi and then restarted the upgrade process with the following commands.

sudo apt-get update
sudo apt-get -y dist-upgrade

Once this had been run the update was finished successfully.

Final steps after upgrade

Once the dist-upgrade has run it is recommended to reboot the Raspberry Pi. Following this reboot this is a good chance to remove any packages that are not used anymore. This can be performed by running the autoremove command below.

sudo apt-get autoremove

Autoremove goes through all the packages that were previously required but not anymore and removes them. For safety you will want to check to see what is being removed in case something is being removed wrongly.

Summary of the upgrade

Upgrading to Raspbian Stretch should be a relatively painless process but it is important to back up your Raspberry Pi before doing so. This will mean that in the rare event during the upgrade you lose data you will be able to restore it. During my upgrades no nodes needed to be reinstalled as the upgrades were fine.

Using the above commands and the noted fixes I was able to upgrade my cluster to Raspbian Stretch.

2 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.