How to put Raspberry Pi 4 in 64-bit mode

I didn't realize that Raspberry Pi 4 worked in 32-bit mode until I compiled MongoDB Embedded. Though Raspberry Pi 4 comes with a 64-bit CPU, it uses 32-bit kernel by default, let alone these userland programs.

Obviously, the compiled MongoDB Embedded was 32-bit too. But fortunately, it was not what I actually want, and after setup 64-bit environment for Raspberry Pi 4 in this post, I can compile a fully-functional MongoDB.

But wait, there seems to be an easier way to put Raspberry Pi 4 to 64-bit mode -- Install Manjaro. However, I don't quite like Arch.

There are basically three steps to get a Raspberry Pi worked in the 64-bit environment.

  1. sudo rpi-update to get a 64-bit kernel.img
  2. Specify 64-bit mode by modifying /boot/config.txt
  3. schroot to get a full 64-bit environment

1. sudo rpi-update to get a 64-bit kernel.img

This is a simple step, the command below is all you need ~ Also, there may be a prompt asking whether you want to continue or not, and just type y.

sudo rpi-update

2. Specify 64-bit mode by modifying /boot/config.txt

The second step is to modify the /boot/config.txt file. We need to specify to VideoCore that we need to boot in 64-bit.

And all we need to do is to add 1 line in /boot/config.txt

arm_64bit=1

Save the file and reboot the Raspberry Pi. After rebooting, the kernel will be 64-bit. You may also validate this by uname -a

Nevertheless, the userland is still in 32-bit. Thus some extra hacking is needed so that we can enter a full 64-bit environment.

3. schroot to get a full 64-bit environment

We need debootstrap to create an initial Debian environment and schroot to create a virtual environment.

sudo apt install -y debootstrap schroot

If you're in China, to use TUNA mirror repo for boosting, apt-transport-https is needed as well.

sudo apt install -y debootstrap schroot apt-transport-https

Now we edit the profile of the virtual environment for schroot

cat << EOF | sudo tee /etc/schroot/chroot.d/pi64
[pi64]
description=V3D arm64 testing
type=directory
directory=/srv/chroot/pi64
users=pi
root-groups=root
profile=desktop
personality=linux
preserve-environment=true
EOF

Then it's time to create the initial Debian environment with debootstrap.

sudo debootstrap --arch arm64 buster /srv/chroot/pi64

Also, you may use TUNA repo to speed up if you're in China.

sudo debootstrap --arch arm64 buster /srv/chroot/pi64 https://mirrors.tuna.tsinghua.edu.cn/debian

This process may be a little bit time-consuming, about 3-5 minutes, which, of course, depends on your Internet connection. Because it will download and install many essential software packages. But once it is done, we will have a 64-bit virtual environment under /srv/chroot/pi64.

The next step is to install sudo to that virtual environment, otherwise, the user pi won't be able to do sudo, given that there is no sudo...

sudo schroot -c pi64 -- apt install -y sudo

Just one more step~

schroot -c pi64

Now, you can do everything you'd usually do with your Raspberry Pi, but in a 64-bit environment.

Leave a Reply

Your email address will not be published. Required fields are marked *

eighteen − seventeen =