Skip to content

Instantly share code, notes, and snippets.

@jauderho
Last active May 7, 2024 21:09
Show Gist options
  • Save jauderho/6b7d42030e264a135450ecc0ba521bd8 to your computer and use it in GitHub Desktop.
Save jauderho/6b7d42030e264a135450ecc0ba521bd8 to your computer and use it in GitHub Desktop.
HOWTO: Upgrade Raspberry Pi OS from Bullseye to Bookworm
### WARNING: READ CAREFULLY BEFORE ATTEMPTING ###
#
# Officially, this is not recommended. YMMV
# https://www.raspberrypi.com/news/bookworm-the-new-version-of-raspberry-pi-os/
#
# This mostly works if you are on 64bit. You are on your own if you are on 32bit or mixed 64/32bit
#
# Credit to anfractuosity and fgimenezm for figuring out additional details for kernels
#
# Make sure everything is up-to-date
sudo apt-get update && sudo apt-get dist-upgrade
# Point to bookworm repos instead
sudo sed -i -e 's/bullseye/bookworm/g' /etc/apt/sources.list
sudo sed -i -e 's/bullseye/bookworm/g' /etc/apt/sources.list.d/raspi.list
# Contents of /etc/apt/sources.list
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
# Uncomment deb-src lines below then 'apt-get update' to enable 'apt-get source'
#deb-src http://deb.debian.org/debian bookworm main contrib non-free
#deb-src http://security.debian.org/debian-security bookworm-security main contrib non-free
#deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free
# Contents of /etc/apt/sources.list.d/raspi.list
deb http://archive.raspberrypi.org/debian/ bookworm main
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspberrypi.org/debian/ bookworm main
# Do actual update
sudo apt update && sudo apt -y full-upgrade && sudo apt -y clean && sudo apt -y autoremove
# Reboot
sudo reboot
# Remove old config files after doing sanity checks
sudo apt purge ?config-files
### Switch to the new kernels ###
#
## WARNING: Since this has bitten several folks. The following can completely brick your system requiring a reinstall
## DO NOT do this if you are unsure
#
# Prep
sudo dpkg --purge --force-depends raspberrypi-kernel raspberrypi-bootloader
sudo umount /boot
sudo fsck -y /boot
sudo mkdir /boot/firmware
sudo sed -i.bak -e "s#boot#boot/firmware#" /etc/fstab
sudo systemctl daemon-reload
sudo mount /boot/firmware
sudo apt install raspi-firmware
# Actually install the kernels. Make sure you pick the right version for your Pi
# sudo apt install linux-image-rpi-v8 linux-headers-rpi-v8 # 64bit
# sudo apt install linux-image-rpi-v7l linux-headers-rpi-v7l # 32bit
# sudo apt install linux-image-rpi-v6 linux-headers-rpi-v6
# Append auto_initramfs=1 to the bottom of file where it says [all]
sudo sed -i.bak '$ a\auto_initramfs=1' /boot/firmware/config.txt
# Reboot
sudo reboot
# Verify using "uname -a" (correct as of 10/2023)
# Old kernel
# Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux
# New kernel
# Linux raspberrypi 6.1.0-rpi4-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.54-1+rpt2 (2023-10-05) aarch64 GNU/Linux
# If you are not converted to using NetworkManager, you might lose networking upon reboot.
# Check the ARP table to see what the new DHCP assigned IP address is. You may have to manually set the IP address again
# Thanks to solsticedhiver for identifying this
#
# Install NetworkManager if not already installed
sudo apt-get install --no-install-recommends network-manager
#
# Switch to NetworkManager from dhcpcd
sudo systemctl enable --now NetworkManager
sudo systemctl disable --now dhcpcd
#
# Set up static IP. Adjust as necessary
sudo nmcli -p connection show
sudo nmcli -p connection show "Wired connection 1"
sudo nmcli con mod "Wired connection 1" ipv4.method manual ipv4.addresses 192.168.1.5/24 ipv4.gateway 192.168.1.1
# Reboot
sudo reboot
#
# Bonus steps
#
# Install btop
sudo apt-get install btop
#
# Update /etc/ssh/sshd_config for up to date, secure by default config. Use ssh-audit to verify
KexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org
HostKeyAlgorithms ssh-ed25519-cert-v01@openssh.com,ssh-ed25519
# Ciphers chacha20-poly1305@openssh.com # Disabled due to CVE-2023-48795 for now
Ciphers aes128-gcm@openssh.com,aes256-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
@joehad83
Copy link

joehad83 commented Mar 10, 2024

If you ignored the below warning and your system is not booting. Are you getting blank screen and the green LED on your Raspberry Pi is flashing 8 times while the red LED is on. It is ok, it can be fixed. Tested on Raspberry Pi 3B+.

## WARNING: Since this has bitten several folks. The following can completely brick your system requiring a reinstall
##          DO NOT do this if you are unsure
  1. Using the Raspbian imager, install a fresh copy on a USB drive (Not your SDcard).
  2. Backup the content of the boot of your SDcard.
  3. Replace the content of the SDcard boot volume with the content of boot volume from the USB drive.
  4. Restore the file cmdline.txt from the backup that you took. (This is important so you can restore the correct PARTUUID)
  5. Put the SDcard back into your Raspberry Pi and check if the problem is resolved.

If your system starts fine but still can't get into your Desktop, hit Ctrl+Alt+F1 to get into your terminal (or use SSH). From there run sudo raspi-config.
Select "Advanced Options" --> "Wayland" --> "Wayfire". Go back to the main screen and hit "Finish" to save and reboot.

@jnorrid
Copy link

jnorrid commented Mar 21, 2024

Worked great for me on a whole rack of 8 4Bs. I would recommend going here: https://www.ssh.com/ssh/sshd_config/ for the latest updates on Ciphers, Algos and MACs as these change quite frequently. The only thing I am disappointed with is that Bookworm still isn't running with GCC-13.2.0 in the stable repo like almost every other distro out there, but I know Debian is all about taking their time in the name of stability. The reason upgrading like this is probably not recommended is that for each step, it may not be cut and dried and you may have to make decisions specific to your system and configuration. For example, whether to keep your custom config files for certain services or to go with the new clean one from updated package maintainers. You definitely need to know what you are doing and you should experiment with a system you don't care too much about before you roll this procedure everywhere IMO. That said, was smooth sailing over here with a couple of additional decisions to make along the way. Thank you to jauderho for the gist - saved me lots of time.

@stdenits
Copy link

stdenits commented Apr 8, 2024

@jnorrid,
Hello, sir.

Could you check and yield your kernel version after update? Is it 6.6.*?

Thanks.

@jnorrid
Copy link

jnorrid commented Apr 8, 2024

Yes @stdenits - no problem. On my system, uname -a yields:

6.6.20+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.20-1+rpt1 (2024-03-07) aarch64

@sonntam
Copy link

sonntam commented Apr 10, 2024

This saved me a bunch of time and worked beautifully on a Pi4B running bullseye on 64bit userland - including the change to the firmware folder. Thank you!

@MarkusEh
Copy link

Thanks for this guide. Worked like a charm, including kernel upgrade (on my 64 bit system).
For NetworkManager, can you remove these lines? For the change to NetworkManager you should do nothing, the system does this after upgrade without any activity.

sudo systemctl enable --now NetworkManager

Will do nothing, as it is enabled after the installation.

sudo systemctl disable --now dhcpcd

Will most likely brake the system. After next reboot, there is no network any more :( . Because dhcpcd will not start (you just disabled it), and NetworkManager has a dependency to dhcpcd in /usr/lib/systemd/system/NetworkManager.service.d/10-dhcpcd.conf:

[Unit]
After=dhcpcd.service
Conflicts=dhcpcd.service

So NetworkManager will not start, as it waits for dhcpcd ...
If you do nothing, dhcpcd starts, and after that, NetworkManager starts and stops dhcpcd due to the Conflicts=dhcpcd.service line.

@solsticedhiver
Copy link

I don't see the file /usr/lib/systemd/system/NetworkManager.service.d/10-dhcpcd.conf on a raspiOS lite 32 bit. What is your OS?

@fmarzocca
Copy link

I don't see the file /usr/lib/systemd/system/NetworkManager.service.d/10-dhcpcd.conf on a raspiOS lite 32 bit. What is your OS?

I have it on a Raspbian Bookworm 32-bit

@solsticedhiver
Copy link

solsticedhiver commented Apr 29, 2024

I just looked at the following images:

  • 2024-03-15-raspios-bookworm-arm64.img.xz
  • 2024-03-15-raspios-bookworm-arm64-lite.img.xz
  • 2024-03-15-raspios-bookworm-armhf.img.xz

available at https://www.raspberrypi.com/software/operating-systems/

And the file is not present in the image themselves. So It must have been added after the first boot or some other way...

May be the instruction must include instead the deletion of that said failed ie.:

rm /usr/lib/systemd/system/NetworkManager.service.d/10-dhcpcd.conf
???

@MarkusEh
Copy link

MarkusEh commented Apr 29, 2024

/lib/systemd/system/NetworkManager.service.d/10-dhcpcd.conf is part of dhcpcd5 1:8.1.2-1+rpt9

This is about upgrading. If dhcpcd5 was part of your "old" OS version, it will be upgraded and available ... . It is not part of a new Bookworm install.

And no, I would not delete this file. You might apt-get remove dhcpcd5, this should work (untested).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment