Skip to content

Instantly share code, notes, and snippets.

@jauderho
Last active July 18, 2024 16:11
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
@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!!

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