Skip to content

Instantly share code, notes, and snippets.

@jauderho
Last active November 14, 2024 20:42
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 [email protected],curve25519-sha256,[email protected]
HostKeyAlgorithms [email protected],ssh-ed25519
# Ciphers [email protected] # Disabled due to CVE-2023-48795 for now
Ciphers [email protected],[email protected]
MACs [email protected],[email protected]
@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).

@odhiambo
Copy link

odhiambo commented May 21, 2024

I have used these instructions to update one of my Pi4s successfully. However, today I am trying to update my other Pi4 and it fails at the 2nd last stage as follows:

root@hass:/home/pi# apt install linux-image-rpi-v8 linux-headers-rpi-v8
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
linux-image-rpi-v8 is already the newest version (1:6.6.28-1+rpt1).
linux-headers-rpi-v8 is already the newest version (1:6.6.28-1+rpt1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
4 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up linux-image-6.6.28+rpt-rpi-v8 (1:6.6.28-1+rpt1) ...
/etc/kernel/postinst.d/dkms:
dkms: running auto installation service for kernel 6.6.28+rpt-rpi-v8.
Sign command: /lib/modules/6.6.28+rpt-rpi-v8/build/scripts/sign-file
Signing key: /var/lib/dkms/mok.key
Public certificate (MOK): /var/lib/dkms/mok.pub

Building module:
Cleaning build area...
make -j4 KERNELRELEASE=6.6.28+rpt-rpi-v8 -C /lib/modules/6.6.28+rpt-rpi-v8/build M=/var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build....(bad exit status: 2)
Error! Bad return status for module build on kernel: 6.6.28+rpt-rpi-v8 (aarch64)
Consult /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/make.log for more information.
Error! One or more modules failed to install during autoinstall.
Refer to previous errors for more information.
dkms: autoinstall for kernel: 6.6.28+rpt-rpi-v8 failed!
run-parts: /etc/kernel/postinst.d/dkms exited with return code 11
dpkg: error processing package linux-image-6.6.28+rpt-rpi-v8 (--configure):
 installed linux-image-6.6.28+rpt-rpi-v8 package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of linux-image-rpi-v8:
 linux-image-rpi-v8 depends on linux-image-6.6.28+rpt-rpi-v8 (= 1:6.6.28-1+rpt1); however:
  Package linux-image-6.6.28+rpt-rpi-v8 is not configured yet.

dpkg: error processing package linux-image-rpi-v8 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-headers-6.6.28+rpt-rpi-v8:
 linux-headers-6.6.28+rpt-rpi-v8 depends on linux-image-6.6.28+rpt-rpi-v8 (= 1:6.6.28-1+rpt1) | linux-image-6.6.28+rpt-rpi-v8-unsigned (= 1:6.6.28-1+rpt1); however:
  Package linux-image-6.6.28+rpt-rpi-v8 is not configured yet.
  Package linux-image-6.6.28+rpt-rpi-v8-unsigned is not installed.

dpkg: error processing package linux-headers-6.6.28+rpt-rpi-v8 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-headers-rpi-v8:
 linux-headers-rpi-v8 depends on linux-headers-6.6.28+rpt-rpi-v8 (= 1:6.6.28-1+rpt1); however:
  Package linux-headers-6.6.28+rpt-rpi-v8 is not configured yet.

dpkg: error processing package linux-headers-rpi-v8 (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 linux-image-6.6.28+rpt-rpi-v8
 linux-image-rpi-v8
 linux-headers-6.6.28+rpt-rpi-v8
 linux-headers-rpi-v8
E: Sub-process /usr/bin/dpkg returned an error code (1)

The error contained in the log - /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/make.log - is:

DKMS make.log for xtrx-0.0.1+git20190320.5ae3a3e-3.2 for kernel 6.6.28+rpt-rpi-v8 (aarch64)
Tue 21 May 15:22:55 EAT 2024
make: Entering directory '/usr/src/linux-headers-6.6.28+rpt-rpi-v8'
  CC [M]  /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.o
/var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c: In function ‘xtrxfd_mmap’:
/var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c:1075:31: error: assignment of read-only member ‘vm_flags’
 1075 |                 vma->vm_flags |= VM_LOCKED;
      |                               ^~
/var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c:1090:31: error: assignment of read-only member ‘vm_flags’
 1090 |                 vma->vm_flags |= VM_IO;
      |                               ^~
/var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c:1115:31: error: assignment of read-only member ‘vm_flags’
 1115 |                 vma->vm_flags |= VM_LOCKED;
      |                               ^~
In file included from /usr/src/linux-headers-6.6.28+rpt-common-rpi/arch/arm64/include/asm/lse.h:12,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/arch/arm64/include/asm/cmpxchg.h:14,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/arch/arm64/include/asm/atomic.h:16,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/include/linux/atomic.h:7,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/include/asm-generic/bitops/atomic.h:5,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/arch/arm64/include/asm/bitops.h:25,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/include/linux/bitops.h:68,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/arch/arm64/include/asm/cache.h:40,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/include/linux/cache.h:6,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/include/linux/time.h:5,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/arch/arm64/include/asm/stat.h:12,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/include/linux/stat.h:6,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/include/linux/module.h:13,
                 from /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c:22:
/var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c: In function ‘xtrx_init’:
/usr/src/linux-headers-6.6.28+rpt-common-rpi/include/linux/export.h:29:22: error: passing argument 1 of ‘class_create’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   29 | #define THIS_MODULE (&__this_module)
      |                     ~^~~~~~~~~~~~~~~
      |                      |
      |                      struct module *
/var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c:1523:35: note: in expansion of macro ‘THIS_MODULE’
 1523 |         xtrx_class = class_create(THIS_MODULE, CLASS_NAME);
      |                                   ^~~~~~~~~~~
In file included from /usr/src/linux-headers-6.6.28+rpt-common-rpi/include/linux/device.h:31,
                 from /usr/src/linux-headers-6.6.28+rpt-common-rpi/include/linux/pci.h:37,
                 from /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c:25:
/usr/src/linux-headers-6.6.28+rpt-common-rpi/include/linux/device/class.h:230:54: note: expected ‘const char *’ but argument is of type ‘struct module *’
  230 | struct class * __must_check class_create(const char *name);
      |                                          ~~~~~~~~~~~~^~~~
/var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.c:1523:22: error: too many arguments to function ‘class_create’
 1523 |         xtrx_class = class_create(THIS_MODULE, CLASS_NAME);
      |                      ^~~~~~~~~~~~
/usr/src/linux-headers-6.6.28+rpt-common-rpi/include/linux/device/class.h:230:29: note: declared here
  230 | struct class * __must_check class_create(const char *name);
      |                             ^~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [/usr/src/linux-headers-6.6.28+rpt-common-rpi/scripts/Makefile.build:248: /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build/xtrx.o] Error 1
make[1]: *** [/usr/src/linux-headers-6.6.28+rpt-common-rpi/Makefile:1938: /var/lib/dkms/xtrx/0.0.1+git20190320.5ae3a3e-3.2/build] Error 2
make: *** [/usr/src/linux-headers-6.6.28+rpt-common-rpi/Makefile:246: __sub-make] Error 2
make: Leaving directory '/usr/src/linux-headers-6.6.28+rpt-rpi-v8'

Is there a way to fix this error?? I do not want to reboot lest I end up with an unusable Pi4

@Firefishy
Copy link

@odhiambo run

sudo apt purge xtrx-dkms
sudo apt install --reinstall  linux-image-rpi-v8 linux-headers-rpi-v8

@odhiambo
Copy link

@odhiambo run

sudo apt purge xtrx-dkms
sudo apt install --reinstall  linux-image-rpi-v8 linux-headers-rpi-v8

Thank you for that, but I already decided to do a clean install. I hope this response will help others.

@datkush420
Copy link

I was able to complete the upgrade on my 4B without issue (headless 64bit). Thank you!

@xKiisa
Copy link

xKiisa commented Jun 9, 2024

Worked great on my Rasperry Pi Zero 2 W, including the kernel :) Thanks for the guide!

@frittenlab
Copy link

Perfect upgrade guide. The only issues I had was switching to the new Network Manager. Thanks

@hereismeaw
Copy link

I tried on my 72 unit of sensecap m1 lora gateway. Work perfectly!!

@victorchen008
Copy link

I tried this update method on my pi 3i, after all the step it is unable to reboot, I used another linux machine to view the bootfs, the kernal.img is missing. Is there any way I can fix this?

@bcutter
Copy link

bcutter commented Jul 29, 2024

I tried this update method on my pi 3i, after all the step it is unable to reboot, I used another linux machine to view the bootfs, the kernal.img is missing. Is there any way I can fix this?

Experienced the same, see https://gist.github.com/jauderho/6b7d42030e264a135450ecc0ba521bd8?permalink_comment_id=4821335#gistcomment-4821335 how I fixed it.

@kraftboy
Copy link

This went perfectly smoothly for me on a Pi4, thanks!

@WhiteRabbit-Code
Copy link

WhiteRabbit-Code commented Aug 13, 2024

sudo sed -i.bak '$ a\auto_initramfs=1' /boot/firmware/config.txt

broke it for me. Raspi didn't boot with auto_initramfs set to 1 anymore. Reverted it to 0 and boot with new kernel was successful.

# Switch to NetworkManager from dhcpcd
sudo systemctl enable --now NetworkManager
sudo systemctl disable --now dhcpcd

Noteable here is that NetworkManager ignores all interfaces defined in /etc/network/interfaces*. The interfaces must be removed from there to get visible in NetworkManager.

Edit: I'm on a Raspberry Pi 2 Model B

@jjamor
Copy link

jjamor commented Aug 17, 2024

Raspberry PI 4 Model B, 64bit, installed in NVMe disk. Just upgraded to bookworm with kernel, without problems :)

@hartacus
Copy link

I've (mostly) followed these steps and now have Bookworm running on my Raspberry Pi model B. Notes:

  • Lines 18-25 (contents of sources.list) only apply to 64-bit installations, not 32-bit installations. Lines 14-16 take care of sources.list based on your current install's bitness so just trust those.
  • I was using an SD card from a fresh bookworm install (backed out of that, too much work) with root on an external SSD that still had bullseye installed. This booted fine with the SD card mounted at /boot, but IPv6 didn't work (I run dual stack). After making a backup copy of /boot, I followed lines 41-59, though I purged raspberrypi-kernel and raspberrypi-bootloader after unmounting /boot instead of before. New kernel (6.6.47+rpt-rpi-v6) installed fine and IPv6 was enabled after reboot.
  • The above issues with IPv6 caused the initial upgrade to fail because my nginx config files had IPv6 addresses. I had to comment those out of the nginx config files then manually install nginx-full which allowed the upgrade to complete successfully.
  • I already had auto_initramfs=1 in my config.txt

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