RSS

Upgrade existing Debian Jessie to Buster, Bullseye, Bookworm without re-image

Upgrade existing Debian Jessie to Buster, Bullseye without re-image on Raspberry Pi, there is no data loss during upgrade with in-place upgrade.

How to do in-place upgrade Debian without data loss

I have a old Raspberry Pi 3 running for many years, it still running on jessie and everything goes well, except I want to install some software which does not exist on jessie.

Since jessie, there are two major releases stretch and buster. It is time to upgrade to my Raspberry Pi OS to keep it up to date.

The official recommendation for major release is re-image.

As this is a major version upgrade, we recommend using a clean image.

However I do not want to re-image SD card since I have exist service running and it take me a lot of time tweak exist system configuration. I do not want to re-configure everything…

Since Raspberry Pi OS is based on Debian, Debian support in-place major release upgrade. This is also mentioned in Raspberry Pi blog raspbian-stretch

Upgrading an existing Jessie image is possible, but is not guaranteed to work in every circumstance. If you wish to try upgrading a Jessie image to Stretch, we strongly recommend taking a backup first – we can accept no responsibility for loss of data from a failed update.

I will take the risk to try this in-place upgrade.

Since there are two major releases, I need upgrade to stretch, then upgrade to buster.

Preparation

  1. Backup the important data is always a good idea in case upgrade failure and can not boot system.
  2. Check free disk space (df -h) before upgrade, OS upgrade normally need extra disk space. Remove unused packages to reduce disk space usage.

jessie to stretch in place upgrade without data loss

Replace jessie with stretch in /etc/apt/sources.list and /etc/apt/sources.list.d/raspi.list:

$ sudo sed -i 's/jessie/stretch/g' /etc/apt/sources.list
$ sudo sed -i 's/jessie/stretch/g' /etc/apt/sources.list.d/raspi.list
$ sudo apt-get update
$ sudo apt-get -y dist-upgrade

Answer yes or no to prompts based your settings.

After dist-upgrade, you may optional install font to fix missing Chinese and Japanese fonts:

$ sudo apt-get install -y fonts-droid-fallback

If you are not using PulseAudio for anything other than Bluetooth audio, remove it from the image by entering

$ sudo apt-get -y purge "pulseaudio*"

The last step is clean apt, remove un-used packages and reboot:

$ sudo apt-get autoremove
$ sudo reboot

stretch to buster in place upgrade without data loss

Similar with jessie to buster, I need replace apt source:

$ sudo sed -i 's/stretch/buster/g' /etc/apt/sources.list
$ sudo sed -i 's/stretch/buster/g' /etc/apt/sources.list.d/raspi.list

Then update:

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

However I got following error this time:

Errors were encountered while processing:
 /tmp/apt-dpkg-install-pxzIiX/152-firmware-misc-nonfree_1%3a20190114-1+rpt4_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

I re-run sudo apt-get -y dist-upgrade and got following errors:

$ sudo apt-get -y dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 firmware-ralink : Depends: firmware-misc-nonfree but it is not installed
N: Ignoring file '50unattended-upgrades.ucftmp' in directory '/etc/apt/apt.conf.d/' as it has an invalid filename extension
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

Follow the instruction, I hope apt --fix-broken install can fix problem:

$ sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  firmware-misc-nonfree firmware-ralink g++-6 gnupg-agent libaio1 libbabeltrace-ctf1 libbind9-140 libboost-filesystem1.62.0 libboost-iostreams1.62.0 libboost-system1.62.0
  libcdio13 libcomerr2 libdns-export162 libdns162 libdrm-freedreno1 libevent-2.0-5 libfile-copy-recursive-perl libglew2.0 libhiredis0.13 libicu57 libisc-export160 libisc160
  libisccc140 libisccfg140 libiso9660-8 libjim0.76 liblwres141 libmpfr4 libperl5.24 libprocps6 libpython3.5 libpython3.5-dev libpython3.5-minimal libpython3.5-stdlib libssl1.0.2
  libstdc++-6-dev libtxc-dxtn-s2tc0 libunistring0 libva-x11-1 libwebpmux2 lynx-cur python-apt python3-pyasn1 python3.5 python3.5-dev python3.5-minimal python3.5-venv rename
  rsync sgml-base xml-core
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  firmware-misc-nonfree
The following NEW packages will be installed:
  firmware-misc-nonfree
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.

Looks good, then I re-run sudo apt-get -y dist-upgrade again, everything goes well this time.

After dist-upgrade success, clean apt and reboot:

$ sudo apt-get autoremove
$ sudo reboot

After reboot, check the release info, you got buster:

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 10 (buster)
Release:	10
Codename:	buster

Continue upgrade to Bullseye

Debian 11.2 (Codenamed: Bullseye) was released on December 18th, 2021. To continue upgrade from Buster to Bullseye, similar with jessie to buster, I need replace apt source:

$ sudo sed -i 's/buster/bullseye/g' /etc/apt/sources.list
$ sudo sed -i 's/buster/bullseye/g' /etc/apt/sources.list.d/raspi.list

Then update:

$ sudo apt-get update   # Update the Bullseye software repositories.
$ sudo apt-get -y dist-upgrade

After dist-upgrade success, clean apt and reboot:

$ sudo apt-get autoremove
$ sudo reboot

After reboot, check the release info, you should have the latest Debian release Bullseye.

During dist-upgrade, you may encounter following error:

The following packages have unmet dependencies:
 libc6-dev : Breaks: libgcc-8-dev (< 8.4.0-2~) but 8.3.0-6+rpi1 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

To fix this, run the following command to upgrade libgcc-8-dev first:

$ sudo apt install libgcc-8-dev
...
...
The following packages have unmet dependencies:
 libgcc-8-dev : Depends: gcc-8-base (= 8.4.0-7+rpi1) but 8.3.0-6+rpi1 is to be installed
                Recommends: libc6-dev (>= 2.13-5) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Actually it also need upgrade gcc-8-base first:

$ sudo apt install gcc-8-base   # Be patient, this take a longer time. Lots of packages (like python, nginx etc.) are upgraded.

After gcc-8-base upgrade success, re-run sudo apt-get -y dist-upgrade to continue upgrade to Bullseye.

Continue upgrade to Bookworm

Debian 12 (Codenamed: Bookworm) was released on June 10th, 2024.

To continue upgrade from Bullseye to Bookworm, similar with previous upgrades, I need replace apt source:

$ sudo sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list
$ sudo sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list.d/raspi.list

Then update:

$ sudo apt-get update   # Update the Bookworm software repositories.
$ sudo apt-get -y dist-upgrade

It may encounter following error during upgrade:

Setting up raspi-firmware (1:1.20250915-1~bookworm) ...
stat: cannot read file system information for '/boot/firmware': No such file or directory
Error: missing /boot/firmware, did you forget to mount it?
dpkg: error processing package raspi-firmware (--configure):
 installed raspi-firmware package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of sense-hat:
 sense-hat depends on raspi-firmware; however:
  Package raspi-firmware is not configured yet.

dpkg: error processing package sense-hat (--configure):
 dependency problems - leaving unconfigured
Processing triggers for initramfs-tools (0.142+rpt4+deb12u3) ...
Errors were encountered while processing:
 raspi-firmware
 sense-hat
needrestart is being skipped since dpkg has failed
E: Sub-process /usr/bin/dpkg returned an error code (1)

The problem is missing /boot/firmware mount point. To fix this, create mount point and mount tmpfs to it:

$ sudo mkdir /boot/firmware
$ mount -t tmpfs -o size=128M firmware /boot/firmware

Then re-run sudo apt-get -y upgrade to continue upgrade to Bookworm.

After success, copy back the firmware files to /boot/firmware from tmpfs:

sudo cp -r /boot/firmware /tmp/
sudo umount /boot/firmware
sudo rm -r /boot/firmware
sudo cp -r /tmp/firmware /boot/firmware

After dist-upgrade success, clean apt and reboot:

$ sudo apt-get autoremove
$ sudo reboot

After reboot, check the release info, you should have the latest Debian release Bookworm.

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 12 (bookworm)
Release:	12
Codename:	bookworm

FAQ

Upgrade without prompts to keep existing config files

During update, it may ask to replace some config files, answer according to your needs, or just keep your current version by default with the following command options:

sudo apt-get -y \
  -o Dpkg::Options::="--force-confdef" \
  -o Dpkg::Options::="--force-confold" \
  dist-upgrade

What this does?

  • --force-confdef Uses the package maintainer’s default action automatically when possible.
  • --force-confold Always keeps your existing config files and prevents prompts.

This combination is the standard, safe way to preserve local configs during unattended upgrades.

Do I need upgrade firmware in OS upgrade?

rpi-update is a tool to get the latest bleeding-edge firmware and kernel for your Raspberry Pi.

The question is should I also upgrade firmware when do OS upgrade?

The short answer is NO.

You should only use rpi-update with a good reason.

This gets you the latest bleeding edge kernel/firmware. There is always the possibility of regressions.

Bug fixes and improvements will eventually make their way into new Raspberry Pi OS releases and apt-get when they are considered sufficiently well tested.

A good reason for using this would be if you like to help with the testing effort, and are happy to risk breakages and submit bug reports. These testers are welcome.

Also if you are suffering from a bug in current firmware (perhaps as one of the reporters of the bug on github or forum) and a fix has been pushed out for testing, then using rpi-update is the right way to get the fix until it makes its way into new Raspberry Pi OS images and apt-get.

Even rpi-update itself not recommend use it as prt of a regular update process. When you run pi-update you got following warning:

$ sudo rpi-update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Performing self-update
 *** Relaunching after update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** We're running for the first time
 *** Backing up files (this will take a few minutes)
 *** Backing up firmware
 *** Backing up modules 5.10.63-v7+
#############################################################
WARNING: This update bumps to rpi-5.10.y linux tree
See: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=288234
'rpi-update' should only be used if there is a specific
reason to do so - for example, a request by a Raspberry Pi
engineer or if you want to help the testing effort
and are comfortable with restoring if there are regressions.

DO NOT use 'rpi-update' as part of a regular update process.

##############################################################
Would you like to proceed? (y/N)

If you really want to continue upgrade firmware, backing up before updating is always advisable.

Avoid SSH disconnection during upgrade

During major release upgrade, lots of packages are upgraded, it may take a long time to finish upgrade and your SSH session may timeout and disconnected.

Add following lines to your local ~/.ssh/config file to keep SSH connection alive:

# Keep SSH session alive, to avoid disconnect from server.
ServerAliveInterval 60   # 1 minute
ServerAliveCountMax 720  # Try 720 times, total 12 hours.

Continue aborted upgrade

If your upgrade process is aborted due to power failure or network issue, you may got following error when re-run sudo apt upgrade:

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

To fix this, just run sudo dpkg --configure -a to continue the upgrade:

$ sudo dpkg --configure -a

References

OmniLock - Block / Hide App on iOS

Block distractive apps from appearing on the Home Screen and App Library, enhance your focus and reduce screen time.

DNS Firewall for iOS and Mac OS

Encrypted your DNS to protect your privacy and firewall to block phishing, malicious domains, block ads in all browsers and apps

Ad