Skip to content

Instantly share code, notes, and snippets.

@jauderho
Last active December 4, 2023 20:54
  • Star 79 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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/
#
# 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 ###
# 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
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
@jauderho
Copy link
Author

jauderho commented Oct 15, 2023

Thanks to @anfractuosity and @fgimenezm for figuring out the kernel bit.

@omerfsen I do not recommend the bulk change from bullseye to bookworm as some repos may not yet have bookworm equivalents. These should be individually verified.

I have updated the gist to reflect these suggestions and have verified on one of my Pis.

@Spanishu
Copy link

Spanishu commented Oct 15, 2023

I ran into a problem running sudo apt install linux-image-rpi-v8 linux-headers-rpi-v8
I get the following error message

sudo apt install linux-image-rpi-v8 linux-headers-rpi-v8
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package linux-image-rpi-v8
E: Unable to locate package linux-headers-rpi-v8

In addition for some strange reason I must have shot my docker containers.

Any suggestion where to look?

@Guerric-P
Copy link

Guerric-P commented Oct 15, 2023

@Spanishu exact same problem here. Probably due to lack of knowledge I tried to rollback the previous steps and reboot, but it never rebooted.

@fgimenezm
Copy link

IMPORTANT: if you already removed the old kernel packages do not reboot until you have a kernel properly installed.

Double check your /etc/apt/sources.list and /etc/apt/sources.list.d/raspi.list and make sure you run "apt update"

You should have something similar to this in /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

and like this in /etc/apt/sources.list.d/raspi.list

deb http://archive.raspberrypi.org/debian/ bookworm main

the new kernel packages come from the http://archive.raspberrypi.org/debian/ repo listed in raspi.list.

Also, make sure you install the one for your raspi model.
linux-image-rpi-v8 is for Raspi 4
For older models you need the other kernels.

older kernel images were named like this:

kernel.img is 32-bit for BCM2835 (RPi1 & Zero)
kernel7.img is 32-bit for BCM2836 (RPi2) and BCM2837 (RPi3)
kernel7l.img is 32-bit for BCM2711 (RPi4)
kernel8.img is 64-bit for BCM2837 (RPi3) or BCM2711 (RPi4)

and the equivalent new kernel packages are

linux-image-rpi-v6
linux-image-rpi-v7
linux-image-rpi-v7l
linux-image-rpi-v8

and there is a linux-image-rpi-2712 which I believe is for Raspi 5.

@Spanishu
Copy link

My /etc/apt/sources.list looks like this

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 deb http://raspbian.raspberrypi.org/raspbian/ bookworm main contrib non-free rpi

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

deb http://archive.raspberrypi.org/debian/ bookworm main

when I run apt update

I get the following error

Hit:1 https://download.docker.com/linux/raspbian bookworm InRelease Hit:2 http://raspbian.raspberrypi.org/raspbian bookworm InRelease Get:3 http://deb.debian.org/debian bookworm InRelease [151 kB] Get:4 http://security.debian.org/debian-security bookworm-security InRelease [48.0 kB] Get:5 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB] Hit:6 http://archive.raspberrypi.org/debian bookworm InRelease Err:4 http://security.debian.org/debian-security bookworm-security InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 54404762BBB6E853 NO_PUBKEY BDE6D2B9216EC7A8 Err:3 http://deb.debian.org/debian bookworm InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0E98404D386FA1D9 NO_PUBKEY 6ED0E7B82643E131 NO_PUBKEY F8D2585B8783D481 Err:5 http://deb.debian.org/debian bookworm-updates InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0E98404D386FA1D9 NO_PUBKEY 6ED0E7B82643E131 Reading package lists... Done W: GPG error: http://security.debian.org/debian-security bookworm-security InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 54404762BBB6E853 NO_PUBKEY BDE6D2B9216EC7A8 E: The repository 'http://security.debian.org/debian-security bookworm-security InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. W: GPG error: http://deb.debian.org/debian bookworm InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0E98404D386FA1D9 NO_PUBKEY 6ED0E7B82643E131 NO_PUBKEY F8D2585B8783D481 E: The repository 'http://deb.debian.org/debian bookworm InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. W: GPG error: http://deb.debian.org/debian bookworm-updates InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0E98404D386FA1D9 NO_PUBKEY 6ED0E7B82643E131 E: The repository 'http://deb.debian.org/debian bookworm-updates InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details.

@odhiambo
Copy link

Tested and worked successfully. Thank you very much.

@fgimenezm
Copy link

@Spanishu , at risk of stating the obvious, you'll have to fix those key errors or you won't be able to find any of the packages.
In fact, if you had those errors you wouldn't have been able to run the initial update steps in the first place and shouldn't have continued.

@Spanishu
Copy link

@fgimenezm thanks. Unfortunately something went really wrong. I have decided to start with a brand new image from scratch. Not ideal but I am at least sure that I have those things covered. Thanks for the help and support!

@solsticedhiver
Copy link

NetworkManager is the new default network manager. So you might want to migrate with something like

systemctl enable --now NetworkManager
systemctl disable --now dhcpcd
nmcli radio wifi
# other nmcli command needed if using cli

not tested

@Wrykoulaka
Copy link

great guide! thank you a lot! however after the upgrade when I try to enable read-only overlay, it also affects my external usb drives instead of just the SD card. Could anyone point me in the right direction to fix it?

@tnorman42
Copy link

I ran into a problem running sudo apt install linux-image-rpi-v8 linux-headers-rpi-v8 I get the following error message

sudo apt install linux-image-rpi-v8 linux-headers-rpi-v8 Reading package lists... Done Building dependency tree... Done Reading state information... Done E: Unable to locate package linux-image-rpi-v8 E: Unable to locate package linux-headers-rpi-v8

In addition for some strange reason I must have shot my docker containers.

Any suggestion where to look?

For me this was because I had a 32 bit version installed on an RPi4. This worked:

sudo apt install linux-image-rpi-v7l linux-headers-rpi-v7l

@patricksmms
Copy link

I'm running into the same, trying to upgrade my raspberry pi 4b, with bullseye 32bits:

pi@raspberrypi:/etc/apt $ sudo apt install linux-image-rpi-v8 linux-headers-rpi-v8
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package linux-image-rpi-v8
E: Unable to locate package linux-headers-rpi-v8

I updated the content of /etc/apt/sources.list and /etc/apt/sources.list.d/raspi.list, then run apt-get update, before running the command above.

Now I'm afraid of rebooting it, as I didn't get the kernel properly installed.

@fgimenezm
Copy link

linux-image-rpi-v8 Is 64bit
Read the comment right before yours

@Mids95
Copy link

Mids95 commented Oct 23, 2023

I've just realized that Raspbian and Raspberry Pi OS are not the same thing. Is that correct?
I tried to update my system using the script but had no success, I wonder if that it's even possible

pi@raspberrypi:~ $ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

@kragil
Copy link

kragil commented Oct 25, 2023

I had problems running Kodi after the upgrade. A rpi-update fixed those.

@shudza
Copy link

shudza commented Oct 26, 2023

Is this working for Desktop installs? Will Wayland just work or any way to do it without Wayland?

@Tos26
Copy link

Tos26 commented Oct 31, 2023

Hello,

About the change on dhcpd or static IP, when the link used is thru SSH (rpi as a server for example), it seems to me better if there is no reboot before the change, isn't it ?

@pdobrien3
Copy link

what is proper content for /etc/apt/sources.list and /etc/apt/sources.list.d/raspi.list?

using:
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

and
deb http://archive.raspberrypi.org/debian/ bookworm main

caused me big problems. Pi 3B+ wouldnt boot. The original post indicates to keep the same repos and just change from bullseye to bookworm

@jauderho
Copy link
Author

jauderho commented Nov 6, 2023

# cat 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

# cat 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

This works with no issue. I have now tried the rev13 process on multiple systems and it appears to mostly work. You may have to hard power-cycle the system to get the network to properly show up.

Another item to note is that the /dev tree may change somewhat. My GPS device moved from /dev/serial0 to /dev/serial1 for instance.

@jauderho
Copy link
Author

This kinda works on a 32bit original Raspberry Pi B.

I did end up having /etc/apt/sources.list configured as

deb http://raspbian.raspberrypi.org/raspbian/ bookworm main contrib non-free rpi

YMMV on this one.

@samveen
Copy link

samveen commented Nov 14, 2023

The guide worked for me with the following caveats:

  • I was already using NetworkManager in Bullseye, so no NM related issues.
  • sudo apt update && sudo apt -y upgrade && sudo apt autoremove && sudo reboot BEFORE changing sources.list*
  • As I knew my lists had bookworm repositories, I changed all sources.list.d files as below (upstream non-free-firmware is NOT required, as firmware blobs are provided by raspi repositories):
    sudo sed -i -e 's/bullseye/bookworm/g' /etc/apt/sources.list /etc/apt/sources.list.d/*.list
    
  • Backup /boot/{cmdline,config}.txt before firmware install process, restore them into /boot/firmware and create links to them in /boot , after firmware install.
  • No reboot until AFTER new kernel install.
  • Disk size of firmware partition was increased as outlined below.

Optional Network Manager pre-prep

  • NetworkManager migration is easier if it is installed and configured when the system is still running Bullseye , so that the upgrade to Bookworm causes no issues with WiFi connections. (same steps as post migration, but in Bullseye)

Optional Firmware partition pre-prep

  • The firmware partition of the Bookwork RaspiOS image is 512M as compared to that of the Bullseye image, which is 256M; this however isn't strictly necessary, as the default firmware uses less than 50M space on the partition.
  • In case this is done for mental satisfaction (like me), Please note that the process to double the size of the boot partition is very time-consuming as data from the partitions need to moved around, and this needs to be done offline, on another machine
  • Change on the GUI via GParted is well documented online.
  • Command-line process to do the same change is as below, with minor time optimization:
    • Reduce the filesystem size of partition 2 to the absolute minimum, to prepare for shrinking the partition
      sudo e2fsck -f /dev/mmcblk0p2  \
          && sudo resize2fs -M  /dev/mmcblk0p2
      ````
      
    • Reduce the partition down to reduced FS size to make free space after the partition - speeds up the part move process (boundary at multiples of 8192 sectors, rounded up, to work around bad SDCard limitations):
      sudo parted /dev/mmcblk0 resizepart 2 $(
        (
          sudo parted /dev/mmcblk0 unit b print; sudo tune2fs -l /dev/mmcblk0p2
        )  | awk  '
              /^Block size/{s=$NF}
              /^Block count/{c=$NF}
              /^\s+2\s+/{b=substr($2, 1, length($2)-1)}
              END{print int((b+(c*s)+8192*512)/(8192*512))*8192*512 "B"}
            '
      )
      
    • Move the partition to leave the required space in the beginning (end value take from Bookworm image- start at 8192 sector + 512M; boundary at multiple of 8192):
      echo '1056768,' | sudo sfdisk --move-data /dev/mmcblk0 -N 2
      
    • Expand the firmware partition to fill empty space:
      growpart /dev/mmcblk0 1
      
    • Resize the firmware partition File system (backup files, mkfs anew, restore files)
    sudo mkdir -p /media/fw-backup/src && \
        sudo  mount /dev/mmcblk0p1 /media/fw-backup/src && \
        sudo  rsync -av /media/fw-backup/src/ /media/fw-backup/dst/ && \
        sudo  umount  /dev/mmcblk0p1 && \
        sudo  mkfs.fat  /dev/mmcblk0p1 && \
        sudo  mount /dev/mmcblk0p1 /media/fw-backup/src && \
        sudo  rsync -av /media/fw-backup/dst/ /media/fw-backup/src/ && \
        sudo  umount  /dev/mmcblk0p1 && \
        sudo rm -fR /media/fw-backup/dst && \
        sudo rmdir -p /media/fw-backup/dst && \
    
    • Expand the root partition back to fill empty space, and expand filesystem back to fill it:
      sudo  growpart /dev/mmcblk0 2
      sudo resize2fs /dev/mmcblk0p2
      

@thomastthai
Copy link

thomastthai commented Nov 18, 2023

@Spanishu and others who get the NO_PUBKEY errors such as NO_PUBKEY 3B4FE6ACC0B21F32 when using sudo apt update, you can try this solution:

To add the missing key, i.e. 3B4FE6ACC0B21F32, use the following command:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 54404762BBB6E853 BDE6D2B9216EC7A8 0E98404D386FA1D9 6ED0E7B82643E131 F8D2585B8783D481

Replace 3B4FE6ACC0B21F32, etc for each missing key. Those were the keys missing in my installation.

There will be a warning about apt-key is deprecated. I've not figured out how to add these keys without using apt-key yet. But at least it got the install going again.

thomas@pi:~ $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 54404762BBB6E853 BDE6D2B9216EC7A8 0E98404D386FA1D9 6ED0E7B82643E131 F8D2585B8783D481
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Executing: /tmp/apt-key-gpghome.IHjmX1k4LA/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 54404762BBB6E853 BDE6D2B9216EC7A8 0E98404D386FA1D9 6ED0E7B82643E131 F8D2585B8783D481
gpg: key F8D2585B8783D481: public key "Debian Stable Release Key (12/bookworm) <debian-release@lists.debian.org>" imported
gpg: key B7C5D7D6350947F8: public key "Debian Archive Automatic Signing Key (12/bookworm) <ftpmaster@debian.org>" imported
gpg: key 73A4F27B8DD47936: public key "Debian Archive Automatic Signing Key (11/bullseye) <ftpmaster@debian.org>" imported
gpg: key 254CF3B5AEC0A8F0: public key "Debian Security Archive Automatic Signing Key (12/bookworm) <ftpmaster@debian.org>" imported
gpg: key A48449044AAD5C5D: public key "Debian Security Archive Automatic Signing Key (11/bullseye) <ftpmaster@debian.org>" imported
gpg: Total number processed: 5
gpg:               imported: 5

Re-run the sudo apt update... line again after those keys are installed.

@thomastthai
Copy link

thomastthai commented Nov 18, 2023

If sudo nmcli -p connection show presents an empty list, you may want to edit /etc/NetworkManager/NetworkManager.conf and look for the section:

[ifupdown]
managed=false

and change managed=true.

sudo service NetworkManager restart
sudo nmcli -p connection show

@jackgit28
Copy link

jackgit28 commented Nov 19, 2023

Thank you and very much appreciated! Lines 33 - 56 sorted the problem I was having!

I'd already successfully upgraded from bullseye to bookworm with a generic guide that wasn't raspberry pi specific. My Pis booted no problem with a working kernel, but whenever I apt update'd and apt upgraded, I got the following errors...

...
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 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 raspi-firmware (1:1.20231024+ds-1+rpt2) ...
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 rpi-eeprom:
 rpi-eeprom depends on raspi-firmware; however:
  Package raspi-firmware is not configured yet.

dpkg: error processing package rpi-eeprom (--configure):
 dependency problems - leaving unconfigured
Processing triggers for initramfs-tools (0.142) ...
Errors were encountered while processing:
 raspi-firmware
 rpi-eeprom
E: Sub-process /usr/bin/dpkg returned an error code (1)

Worked on various generation Raspberry PIs (1->4), taking care to choose the right architecture for the new kernel.

Resolved with thanks!

@thomastthai
Copy link

thomastthai commented Nov 20, 2023

For the few users getting the error:

pi@raspberrypi:/etc/apt $ sudo apt install linux-image-rpi-v8 linux-headers-rpi-v8
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package linux-image-rpi-v8
E: Unable to locate package linux-headers-rpi-v8

It is likely you are upgrading from 32-bit to 64-bit or previously upgraded and saw your kernel with 64-bit, but didn't know your userland binaries were still using 32-bit.

You can verify by:

sudo dpkg --print-architecture

Which will likely show: armhf.

Then do:

sudo apt list linux-image-rpi*

You'll likely see all *armhf (32-bit) lines.

Since the package system is using 32-bit, it won't pull the needed 64-bit packages, including the kernel you want.

Check to see if you have another architecture enabled using:

sudo dpkg --print-foreign-architecture

It's likely blank.

If you want to add that 64-bit kernel:

sudo dpkg --add-architecture arm64

Then see the 64-bit package lists available for the kernel:

sudo apt list linux-image-rpi*

Now you should see the ...-V8 along with other *arm64 versions.

You can upgrade the kernel now, BUT you'll still be stuck with 32-bit userland binaries. Cross-grading from 32-bit to 64-bit can be done but it is tedious and requires around 6 to 8 hours for someone who has the skills. IMHO, it's not worth the time. You'll save a lot of time backing up your /home, /etc, /var, and other important directories or files along with the packages you installed. Install a fresh Bookworm 64-bit image, copy the backup files and directories over, and install those needed packages.

Updates:
2023-11-23 -- Seems the copy and paste with -- had some issues so I retyped the -- above to save you some errors.

@stevehoek
Copy link

For the few users getting the error:

pi@raspberrypi:/etc/apt $ sudo apt install linux-image-rpi-v8 linux-headers-rpi-v8
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package linux-image-rpi-v8
E: Unable to locate package linux-headers-rpi-v8

It is likely you are upgrading from 32-bit to 64-bit or previously upgraded and saw your kernel with 64-bit, but didn't know your userland binaries were still using 32-bit.

You can verify by:

sudo dpkg ‐-print-architecture

Which will likely show: armhf.

Then do:

sudo apt list linux-image-rpi*

You'll likely see all *armhf (32-bit) lines.

Since the package system is using 32-bit, it won't pull the needed 64-bit packages, including the kernel you want.

Check to see if you have another architecture enabled using:

sudo dpkg ‐-print-foreign-architecture

It's likely blank.

If you want to add that 64-bit kernel:

sudo dpkg ‐-add-architecture arm64

Then see the 64-bit package lists available for the kernel:

sudo apt list linux-image-rpi*

Now you should see the ...-V8 along with other *arm64 versions.

You can upgrade the kernel now, BUT you'll still be stuck with 32-bit userland binaries. [Cross-grading]

I am running Raspbian Homebridge version of Raspbian. I followed the instructions here and got the message about 'unable to locate package' for the v8 (arm64) kernel

I installed the v7 (32bit) kernel and its working, but on a clone of this Rpi that has not been upgraded it was a 64bit kernel and 32bit userland. I'd like to get this system back to that, but when I run

sudo dpkg ‐-add-architecture arm64

it says

dpkg: error: need an action option

any ideas?

@bl8
Copy link

bl8 commented Nov 22, 2023

but when I run

sudo dpkg ‐-add-architecture arm64

it says

dpkg: error: need an action option

It seem the comment from @thomastthai has an incorrect character in place of the first "-" in the various sudo dpkg --something commands. It looks almost identical (depending on the font), but it will cause this error if you've copy/pasted the command.
You just need to delete the two dash characters and type them yourself.

@stevehoek
Copy link

stevehoek commented Nov 23, 2023

but when I run
sudo dpkg ‐-add-architecture arm64
it says
dpkg: error: need an action option

It seem the comment from @thomastthai has an incorrect character in place of the first "-" in the various sudo dpkg --something commands. It looks almost identical (depending on the font), but it will cause this error if you've copy/pasted the command. You just need to delete the two dash characters and type them yourself.

Thank you, that did allow me to add the arm64 architecture, but when I try to

sudo apt install linux-image-rpi-v8 linux-headers-rpi-v8

it still gives me an error that it is not found
When I try to do a

sudo apt update

I get new warnings about a deprecated key and notes like this

N: Skipping acquire of configured file 'main/binary-arm64/Packages' as repository 'http://raspbian.raspberrypi.org/raspbian bookworm InRelease' doesn't support architecture 'arm64'

@patricksmms
Copy link

patricksmms commented Nov 23, 2023

@fgimenezm

linux-image-rpi-v8 Is 64bit Read the comment right before yours

I know. I tired also to run instead:

sudo apt install linux-image-rpi-v7l linux-headers-rpi-v7l

But had the same result.

I ended up with a fresh install.

Perhaps there is already a solution on the comments above, but I reinstalled it a few weeks ago.

@rshev
Copy link

rshev commented Dec 4, 2023

Awesome guide, thank you!
My 5c - upgraded my two Pis, the prickliest part was the NetworkManager in both cases.

In one case the machine was unable to connect even via cable after switching off dhcpcd, managed to revert via booting from SD card, mounting my SSD and doing

sudo chroot /mountdir sh
sudo systemctl enable dhcpcd

Afterwards I found that the correct way to switch to NetworkManager is to use raspi-config, which worked like a charm.

For Pi 5 there is a 2712 kernel, but it works with v8 as well.

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