~ 7 min read

Installing OpenBSD on a Raspberry Pi4

How to install OpenBSD on Raspberry Pi4 in 2024 without using a serial adapter

Installing OpenBSD on a Raspberry Pi 4 has been a challenge for me, specifically with respect to setting up the EFI boot partition. U-Boot is not working as of 05/27/2024, and although most people advise using EDK II, information about how to install it is quite outdated. This article describes how to install OpenBSD on an RPi4 in 2024. If you have any questions and/or want to contribute, you can contact me through any of the social media that appear in this blog. All references can be found at the end of the document in case you need them. Let’s start!

Ingredients

  • 1 Raspberry Pi4
  • 1 micro SD card
  • 1 USB drive
  • HDMI cable
  • Keyboard & mouse
  • Operating system running GNU/Linux or similar

Preparation

The first step is to install Pi OS on a microSD card. You can use the same SD card that OpenBSD will be used for installation, but you can use another if you want to keep Pi OS, which could be really useful.

  1. Install Pi OS on a microSD card

Let’s download the latest Raspberry Pi OS version first:

wget -O - https://downloads.raspberrypi.com/raspios_armhf/images/raspios_armhf-2024-07-04/2024-07-04-raspios-bookworm-armhf.img.xz > rpiimage.img.xz && xz -d rpiimage.img.xz

Then, write this image into the microSD card. Before that, check the device name, it’s something like /dev/sdX (In my case, it is /dev/sdc):

lsblk

Before anything else, don’t forget to unmount the microSD card first:

sudo umount /dev/sdX

Now, let’s write the image to the microSD card (replace /dev/sdX):

sudo dd if=rpiimage.img of=/dev/sdX bs=4M status=progress
  1. Update Pi OS

Connect a keyboard, mouse, and HDMI cable to the Raspberry Pi. Insert the microSD card into the Raspberry Pi 4 and power it on. After selecting the options and configurations you think are necessary, update the system (keep in mind this will take a long time):

sudo apt update && sudo apt full-upgrade -y
sudo apt install rpi-eeprom
sudo rpi-eeprom-update
  1. EEPROM configuration

Now, configure the EEPROM version to latest by executing:

sudo raspi-config

and select latest in

Advanced Options -> Bootloader Version

It will ask us to reboot, but you will choose not to.

Finally, update the EEPROM and reboot.

sudo rpi-eeprom-update -a
reboot
  1. Set the Boot Order

The final step in the preparation is to configure the boot order to give the USB drive the highest priority. Next, execute the following for this purpose.

sudo raspi-config

Then, select the option USB Boot in

Advanced Options -> Boot Order

Then, exit, and it will ask if you want to reboot, so choose yes. After the reboot, you can verify the boot order.

sudo rpi-eeprom-config

If there’s a line that appears like this, then the preparation was done correctly:

BOOT_ORDER=0xf14 # Distinto de 0xf41

Installation

  1. Obtain the ARM image of OpenBSD and verify it

Now, download the OpenBSD image, which at the time of writing this article is in version 7.5. If there’s a new update, you can try installing that version and see if it works (I would appreciate it if you could send me a message letting me know ;)):

wget https://cdn.openbsd.org/pub/OpenBSD/7.5/arm64/install75.img

Finally, verify the installation if you wish (you can skip this step if you want).

wget https://cdn.openbsd.org/pub/OpenBSD/7.5/arm64/SHA256
sha256sum -c --ignore-mising SHA256

If the output is install75.img: OK, then there has been no error.

  1. Get the EDK II bootloader

We will use the EDKII bootloader version compiled for RPi4 (at the time of writing this article, it is version 1.37). Let’s download it in the following way:

wget https://github.com/pftf/RPi4/releases/download/v1.37/RPi4_UEFI_Firmware_v1.37.zip
  1. Copy the installation image to the USB drive

Now, copy the OpenBSD 7.5 image to the USB drive using the dd command again.

sudo dd if=install75.img of=/dev/sdX bs=4M status=progress

Where /dev/sdX refers to the USB drive file. One must take extreme care with the letter chosen, as dd will overwrite the device. Use lsblk to check that the correct file has been selected.

Additionally, we are going to delete the data from the microSD card where OpenBSD will be installed (though this is optional). As mentioned before, be very careful with the device file.

sudo dd if=/dev/zero of=/dev/sdX bs=4M status=progress
  1. Replace the boot partition on the USB drive and eject it

After that, replace the boot partition with U-Boot on the USB drive with EDK II. For this, first mount the boot partition (X is the device letter). Unfortunately, the only way I’ve been able to identify the boot partition is through trial and error. In my case, it ended up being /dev/sdb9.

sudo mount -o -t msdos /dev/sdXX /mnt

Then, you have to delete all files except the efi folder. The way to do this is by moving the folder to /tmp and deleting all files in the mount point. Next, move the efi folder back to its original directory.

sudo mv /mnt/efi /tmp
sudo rm -fr /mnt/*
sudo mv /tmp/efi /mnt

Finally, extract the contents of the zip file containing EDK II into the mounted directory. Lastly, unmount the device:

sudo unzip -x ./UEFI-1.37.zip -d /mnt
sudo umount /mnt

Installation of OpenBSD on the SD card

  1. Connect a keyboard, the USB drive, the HDMI cable, the SD card, and connect an Ethernet cable

This is the best part, the installation of OpenBSD. First, we connect the USB drive with the installer, a keyboard, the HDMI cable, and an Ethernet cable. Once everything is connected, we power on the Raspberry Pi 4. When the Raspberry image appears, press the <esc> key. This will cause the bootloader to enter a screen similar to the BIOS. It might take a long time or a short time depending on the devices used, so you need to stay alert.

Then, connect the microSD card where OpenBSD will be install. Doing it this way ensures that the boot process starts from the device with the EDK II firmware.

On the BIOS screen, select the Boot Manager option and then the USB drive that contains the installation image.

  1. Install OpenBSD on the SD card; be careful with the disks!

Now install OpenBSD on the microSD card. Upon starting, you will encounter a prompt and choose the install option. The installation process is quite straightforward. There are two issues that might arise:

  • Be careful with the disks. Carefully review the disk where the operating system will be installed to avoid overwriting the USB drive being used.
  • If there’s an error when selecting repositories, my solution was to change the CDN from where the packages will be downloaded.

At the end of the installation, you’ll encounter this prompt. Choose the option (S)hell:

Exit to (S)hell, (H)alt or (R)eboot?

Execute the following commands to set the console and power off the Raspberry Pi 4, respectively:

echo 'set tty fb0' > /mnt/etc/boot.conf
halt -p
  1. Replace the firmware in the new system

To replace the firmware in the new system, many copy the bootloader from the Raspberry Pi, but this didn’t work for me. Therefore, I did it from my PC.

First, mount the partition on the SD card that contains our new OpenBSD 7.5 installation. Again, through trial and error, in my case, the boot partition was /dev/sdb9:

sudo mount -o -t msdos /dev/sdXX /mnt

Then copy the bootloader as you did before (Replace path with the path where you downloaded the firmware).

sudo mv /mnt/efi /tmp
sudo rm -fr /mnt/*
sudo mv /tmp/efi /mnt
sudo unzip -x /path/to/UEFI-1.37.zip -d /mnt

As a final step, unmount the partition:

sudo umount /mnt

Post instalación

Having completed the installation, we can make some optional changes by going to Device Manager > Raspberry Pi Configuration > Advanced Configuration in the BIOS (by pressing Esc when starting the Raspberry Pi 4).

On one hand, you can remove the 3GB RAM limit.

"Limit RAM to 3 GB" ----> "Disabled"

On the other hand, if you are going to use Wi-Fi, you have to enable the following option. However, do this after setting up a wireless network connection, as unfortunately, you can’t use the monitor and wifi simultaneously (meaning the only option left would be to access it via SSH).

"System Table Selection" ----> "Devicetree"

Finally, press F10 to save, then <Esc> repeatedly and select Reset to reboot.

Conclusion

That’s it! Now you can enjoy the security that OpenBSD provides along with the convenience of having a Raspberry Pi 4 at the same time. There are many things you can do; here are some examples:

  • Update system and firmware
  • Install packages like zsh, vim, neofetch, htop, lsblk
  • Configure chrony, history, doas
  • Create an apache/nginx webserver
  • Set up a firewall (pf)
  • Change shell
  • Configure a wireless connection and enable sshd
  • Configure SMTP
  • … and more!

If this article has been helpful to you, you can share it on a social network to support me ^-^. In case you find an error or bug, don’t hesitate to send me an email or a message. Thank you very much for reading!

References

  • openbsdhandbook.com
  • mtsapv.com/rpi4obsd
  • undeadly.org/cgi?action=article&sid=20170409123528
  • github.com/AshyIsMe/openbsd-rpi4
Share: