How To Upgrade Raspbian To A 64 Bit Kernel

At the time of this writing, there is no 64 bit edition of Raspbian yet. This is particularly bad if you are running Docker (or Kubernetes) on the new Raspberry Pi Model 4, because you will not be able to run the many ARM64 images on Docker Hub, e.g. OpenJDK. Fear not, you can change this! Here is how.

It’ll be a long way before a 64 bit edition of Raspbian gets released. However, thanks to the recent work of the Raspberry Foundation, you can now upgrade to a beta version of a 64 bit Linux kernel. This upgrade will not change the installed executables in your system, but at least the upgraded 64 bit kernel can run new 64 bit executables as well as any old 32 bit executables.

Before, you would have to try third party OS images to get a 64 bit Linux kernel. I have tried some with mixed results. The best alternative I have found so far is an unofficial image for Ubuntu Server 18.04.3, which has been created and described in a blog posting by James A. Chambers. However, the new hardware of the RPi 4 is not yet fully supported, so I thought I should give Raspbian another try.

Before you do this, be warned: This is beta software, so things may break! Retain your current OS image so that you can revert anytime if there is trouble. Now, for the upgrade, login to your RPi and enter:

$ sudo rpi-update

This will initiate the upgrade operation. At some point, it will ask you to type a single y or n character to confirm the upgrade or not. For tools like Ansible etc, you can simply automate a positive answer like this:

$ echo -n y | sudo rpi-update

The 64 bit kernel will not be loaded upon boot until you also edit the file /boot/config.txt to contain the following line:

arm_64bit=1

When testing this, I found a problem which is specific to Kubernetes: Containers could not connect to the Internet anymore. This is because the upgrade breaks iptables. There is a trivial fix for this, however:

$ update-alternatives --set iptables /usr/sbin/iptables-legacy
$ update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

Next, you need to reboot the system:

$ sudo reboot

Finally, you can check the upgraded kernel:

$ uname -r
Linux node-3 4.19.73-v8+ #1267 SMP PREEMPT Fri Sep 20 18:14:38 BST 2019 aarch64 GNU/Linux

aarch64 is a synonym for ARM64v8 - sweet!

Enjoy!