Skip to content

Instantly share code, notes, and snippets.

@samveen
Forked from jauderho/gist:6b7d42030e264a135450ecc0ba521bd8
Last active March 12, 2024 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samveen/9015d8905a703614084f1a9ec5c9a8c0 to your computer and use it in GitHub Desktop.
Save samveen/9015d8905a703614084f1a9ec5c9a8c0 to your computer and use it in GitHub Desktop.
HOWTO: Upgrade Raspberry Pi OS from bullseye to bookworm
### WARNING: READ CAREFULLY BEFORE ATTEMPTING ###
#
# Credit to anfractuosity and fgimenezm for figuring out additional details for kernels
#
# Make sure everything is up-to-date
sudo apt update && sudo apt -y dist-upgrade && sudo apt -y autoremove && sudo apt -y clean
# Reboot once to ensure the running state uses the latest of everything.
sudo reboot
# Change all repos from bullseye to bookworm
sudo sed -i -e 's/bullseye/bookworm/g' /etc/apt/sources.list /etc/apt/sources.list.d/*.list
cat <<_ENDL
### Check contents of /etc/apt/sources.list against below:
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
### Check contents of /etc/apt/sources.list.d/raspi.list against below:
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
_ENDL
# Do actual update
sudo apt update && sudo apt -y full-upgrade && sudo apt -y clean && sudo apt -y autoremove
# Reboot, but can be delayed till after bootloader and kernel update
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
## DO NOT RESTART ANY SERVICES WHEN PROMPTED - systemd is in poor state till pi restarts.
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
# Set up a new WiFi connection:
# sudo nmcli con add type wifi con-name MFSL ssid MFSL wifi-sec.key-mgmt wpa-psk wifi-sec.psk MixedFruitS@l@d save yes
# Remove obsolete link to service file left by aspberrypi-net-mods of bullseye , removed in bookworm.
# Ref: https://github.com/RPi-Distro/raspberrypi-net-mods/
sudo rm -f /etc/systemd/system/multi-user.target.wants/raspberrypi-net-mods.service
# Reboot
sudo reboot
#
# Bonus steps
#
# Check packages not installed from bookworm release repositories (any source)
dpkg --get-selections |awk '{print $1}'| \
xargs -rn9 bash -c 'apt show $0 "$@" 2>/dev/null| \
grep -E "^Package|^APT-"' | grep -v " bookworm" |grep -B2 '^APT-Sources:'
# Install btop
sudo apt-get install btop
cat <<_ENDL
# 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
_ENDL
@samveen
Copy link
Author

samveen commented Nov 27, 2023

Minor QOL updates to fork

@samveen
Copy link
Author

samveen commented Dec 27, 2023

  • Added warning comment
  • Added check for non-bookworm packages.

@samveen
Copy link
Author

samveen commented Mar 12, 2024

  • Added cleanup for a link to removed systemd unit of raspberrypi-net-mods (obsoleted by NetworkManager transition, and removed in the bookworm version of the package)

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