🌘

喔优秀. Wow! Excellent!

Crossgrade Ubuntu on a Raspberry Pi

The materials contained in this web site are for information purposes only. I expressly disclaim all liability to any person in respect of anything and in respect of the consequences of anything done or omitted to be done wholly or partly in reliance upon the whole or any part of the contents of this web site. I am not responsible for any third party contents which can be accessed through this web site.

Prep Info

This tutorial will guide you crossgrade your 32bint Ubuntu installation to 64bit on a RaspberryPi 3B+.

32bit architechure on RaspberryPi 3B+ is known as armhf which is a ‘hard float’ version of armv7, 64bit is called arm64 or aarch64.

Main process

Install arm64 bootloader (aka U-Boot) and arm64 linux kernel — Boot into the arm64 kernel — Replace all the packages with their arm64 counterparts

Step by step

  1. Change to root user
su
  1. Enable the ablility to install arm64 packages in dpkg and apt.
dpkg --add-architecture arm64
  1. Use apt install the arm64 version U-Boot package, then install arm64 linux kernel, which support both 32bit & 64bit userland tools.
apt update
apt install u-boot-rpi:arm64 u-boot-tools:arm64 linux-image-raspi:arm64
  1. Go to the firmware partion on your SDCard (or on your USB Drive, in case you are using USB Boot), where the bootloader and its configurations are locate.
# SDCard mount points
# lsblk | grep mmcblk0
# mmcblk0     179:0    0  7.4G  0 disk 
# |-mmcblk0p1 179:1    0  256M  0 part /boot/firmware
# `-mmcblk0p2 179:2    0  7.2G  0 part /
cd /boot/firmware
  1. Check and make sure the bootloader is configured correctly. Take a closer look at the config.txt file, make sure in the [pi3] section kernel equals to uboot_rpi_3.bin and in the [all] section the line arm_64bit=1 is presented. Make sure the binary file uboot_rpi_3.bin is actually in the bootloader partion.
# Sample output
ls -al | grep .bin
# -rwxr-xr-x 1 root root    52456 Feb  2 04:35 bootcode.bin
# -rwxr-xr-x 1 root root    52456 Jan 18 12:11 bootcode.bin.bak
# -rwxr-xr-x 1 root root   466672 Jan 18 07:30 uboot_rpi_2.bin
# -rwxr-xr-x 1 root root   516416 Jan 18 07:30 uboot_rpi_3.bin
# -rwxr-xr-x 1 root root   479120 Jan 18 07:30 uboot_rpi_3_32b.bin
# -rwxr-xr-x 1 root root   572064 Jan 18 07:30 uboot_rpi_4.bin
# -rwxr-xr-x 1 root root   536140 Jan 18 07:30 uboot_rpi_4_32b.bin
# -rwxr-xr-x 1 root root   558456 Jan 18 07:30 uboot_rpi_arm64.bin
# An original configuration file from stock 64bit Ubuntu RPI3B+ system image.
cat config.txt

# ...
[pi4]
kernel=uboot_rpi_4.bin
max_framebuffers=2

[pi2]
kernel=uboot_rpi_2.bin

[pi3]
kernel=uboot_rpi_3.bin

[all]
arm_64bit=1
device_tree_address=0x03000000
# ...
enable_uart=1
cmdline=cmdline.txt

include syscfg.txt
include usercfg.txt
  1. Reboot. You should boot directly into your new arm64 kernel.
# After reboot login as root
arch
# aarch64
  1. Download latest arm64 dpkg tar apt and apt-utils with their dependences. Then go to /var/cache/apt/archives/ and install these packages offline manually.(After installation, dpkg will see armhf as foreign architecture)
apt clean
apt --download-only install dpkg:arm64 tar:arm64 apt:arm64 apt-utils:arm64
cd /var/cache/apt/archives/
dpkg -i *.deb
  1. Fix broken. Do serveral apt –fix-broken install commands. CAUTION! You really need to pay attention to what apt:arm64 attempt to install or remove, you shall stop when you spot apt:arm64 trying to install its 32bit counterpart apt:armhf while it is trying to remove itself. Go back to /var/cache/apt/archives/ reinstall apt and apt-utils. After that you should manually check package dependences and fix them, then do an apt full-upgrade.
apt --fix-broken install
# ...
# cd /var/cache/apt/archives/
# dpkg -i apt*
apt full-upgrade
  1. Crossgrade all the other armhf packages to arm64, reboot, then purge all the armhf packages.
# Make sure default arch has been changed
dpkg --print-architecture
# arm64
dpkg --print-foreign-architectures
# armhf

apt install $(dpkg -l | grep '^.i.*:armhf' | grep :armhf | sed -e s/:armhf/:amd64/ | awk '{print $2}')
reboot
#...
apt purge $(dpkg -l | grep '^.i.*:armhf' | awk '{print $2}')
  1. Remove the armhf architecture. Done!
dpkg --remove-architecture armhf
apt update

Optional

You can keep the armhf architecture and some armhf packages.In case some packages do not provide arm64 version, and you need them. Use tty console cable connect to the RaspberryPi, unstable ssh connection may cause unnecessary trouble during the crossgrade process. Besides, you may want to install man-db and some network related service packages at last. Because, first, man-db will be temperory broken if you have not installed its dependences, and you will not be able to use man to check manuals when you forget something, second, if something go wrong with the service packages that related to network, you may not be able to connect to the internet, therefore you can not use apt to install packages online anymore, and you will need another computer to fix this broken.

Reference

[1]. Debian Wiki CrossGrading

[2]. Ubuntu RaspberryPi Wiki Multiarch

[3]. Is it possible to “upgrade” from a 32bit to a 64bit installation? the answer by Asterix on AskUbuntu.com

[4]. Convert from armhf to arm64 on Raspberry Pi 3 B running 64-bit Ubuntu Server 18.04 LTS (Bionic) the answer by moonwalker on AskUbuntu.com

— Feb 5, 2022