Install 64 bit OS on Raspberry Pi 4
This article will help you install the new Raspberry 64-bit operating system on Raspberry Pi 4. Although written for the Raspberry Pi 4, the guide can also be used without any modification for the Raspberry 3. The Raspberry 2 and 1 have 32- bit CPUs and therefore are unable to run a 64-bit OS. The 64-bit operating system is, of course, the natural next step in the ongoing Raspberry Pi evolution. The operating system will be further developed over time. For now, the Raspberry Foundation has released a more than functional beta version to get started.
Why not use Ubuntu?
Well, there is nothing wrong about Ubuntu. The Raspberry Imager has even options to install different Ubuntu versions.
However, Ubuntu being a mature operating system and suitable for a wide range of processors, is not what you can say very lightweight. The new 64-bit Raspberry operating system outperforms Ubuntu systematically when it comes to speed. Especially in our deep learning applications. That's the reason why we choose to run the 64-bit Raspberry OS, even while it is still in development.
The first step in installing a 64-bit OS on your Raspberry Pi 4 is to download the new Raspberry Pi Image Tool from this site. The Image Tool can write an operating system of your choice on an SD card. At the same time, it will format the card into the correct ext4 for the Raspberry Pi, even a large 64, 128 or even 256 GByte card. Different image formats are supported, making this tool a better alternative to balena Etcher.
The second step is downloading the correct 64-bit OS for your Raspberry Pi 4. At the moment, the latest version is the 2020-05-27-raspios-buster-arm64 version which can be downloaded here.
The slideshow below shows how easy the whole image writing process is.
- Select the operating system dialogue.
- In the drop-down list select the custom option and find the 2020-05-27-raspios-buster-arm64.zip you just downloaded.
- Select the SD card.
- Here, we used a 64 Gbyte SD card.
- Start the erase, format and writing action.
- You can follow the progress.
After writing your 64-bit image, you can insert the SD card into the Raspberry and boot. Follow all instructions and make sure that the startup procedure is checked for software updates. As the 64-bit operating system is under development, there will inevitably be some new ones.
Time for a version check now. Please give the command uname -a and check your version.
You also need to check your C++ compiler version with the command gcc -v. It must also be an aarch64-linux-gnu version, as shown in the screenshot. Earlier 64-bit versions of the Raspberry OS still had an old 32-bit C++ compiler (arm-linux-gnueabihf). You must have a 64-bit C++ compiler as we are going to build software from scratch. Otherwise, there is no point in building a 32-bit version on a 64 machine.
The last action before using the 64-bit operating system on the Raspberry Pi 4 is changing the memory swapping. Memory swapping increases your working memory by temporarily placing infrequently used parts in a file on your SD card. In this way, memory is released. Once the tasks are completed, the original content is replaced from the file into memory, hence the name 'swapping'.
There are two minor issues with switching memory to the SD card. First, it is not a very fast mechanism because transferring data to flash memory is slow. Second, it can quickly wear out your SD card due to the limited number of write actions a flash memory can endure.
When you occasionally switch between web pages in Chromium, data is only transferred once. This has no impact on the lifespan of the flash memory whatsoever. On the other hand, when you compile a large software package, such as TensorFlow, you may have huge amounts of data constantly transferring between flash and memory, causing your SD card to deteriorate very quickly. See the Protect the Raspberry Pi 4 SD flashcard page for more inside information on this topic.
To solve the problems with memory swapping, we use zram. Instead of writing parts of the memory to the flashcard, zram compresses these parts to a zip file and saves the result back to RAM. The difference in the size of the compressed data and the original size is the amount of memory that is released. That may sound cumbersome, but in practice, it is a much faster mechanism than writing to flash memory. The only limitation is ultimately the size of your RAM when there is no more space to store even larger compressed files. On the other hand, the original Raspberry Pi dphys-swap file is limited to 2 Gbyte flash memory.
Another discussion is whether we need memory exchange in the first place. If you have 8 GB of RAM onboard, there is rarely any reason to swap memory. You can try to work without. You probably never have a problem. If you have 2 or 4 Gbyte, you better install zram.
Follow the next steps to install zram on your 64-bit operating system. Note the ampersand on the last line. Do not forget this character, otherwise the bootup will not continue.
# remove the old dphys version
$ sudo /etc/init.d/dphys-swapfile stop
$ sudo apt-get remove --purge dphys-swapfile
# install zram
$ sudo wget -O /usr/bin/zram.sh https://raw.githubusercontent.com/novaspirit/rpi_zram/master/zram.sh
$ sudo chmod +x /usr/bin/zram.sh
# set autoload
$ sudo nano /etc/rc.local
# add the next line before exit 0
# save with <Ctrl+X>, <Y> and <Enter>
Last action will be setting the upper limit zram will use. This can be done with the next commands.
$ sudo nano /usr/bin/zram.sh
# alter the limit with * 2
mem=$(( ($totalmem / $cores)* 1024 * 2))
# save with <Ctrl+X>, <Y> and <Enter>
After a reboot, all actions have now been taken and the 64-bit operating system is up and running on Raspberry Pi 4.
Overclocking the 64-bit operating system can be done in the same way as with the 32-bit version. For more information see: Safe overclocking of the Raspberry Pi 4 to 2 GHz. Keep in mind that you don't have NOOBS now with its easy to use recovery menu. If the system freezes or crashes due to overclocking, the only way to change the frequency is to use another computer that can modify the /boot/config.txt file on the SD card.
The Raspberry 64-bit operating system is still under development. For example, at the time of writing, Raspistill is working but crashes when the image needs to be saved. VNC is not yet available for this OS. Also, there will undoubtedly be many improvements planned.
It is good practice to check for updates every week with known commands.
# refresh your OS
$ sudo apt-get update
$ sudo apt-get upgrade