Tutorial: Build OPNsense ARM64 images on a RPI4
It has been a long time since the opnsense/tools can build ARM64 images.
While some find it troublesome to cross-build the ARM64 image from an AMD64 machine, I have always built the images on an ARM64 machine. Usually, I use a KVM virtual machine on my Radxa Rock5b, with the four Cortex-A76 cores of RK3588, 12G of memory, and pass-through access to SSD storage; it works like a charm and finishes a fresh new build in 20 hours.
A Raspberry Pi 4B with 4G of memory or above is also more than enough to build the image. As an RPI4 would be more common than an RK3588 board, I will write a tutorial on how to build the image on an RPI4.
1 Prepare the hardware
First of all, we need to prepare the hardware:
- an RPI4 with 4G or 8G would be good
- a suitable heatsink for your RPI4
- a power supply that can hold the RPI4 and the storage device
- at least 32G of storage, an SD card, or an SSD drive with USB3.0 to SATA adapter would be much better
- Internet access through Ethernet
- a USB to tty cable to interact with the console; you can also use a monitor and a keyboard instead
- a master machine with Linux or FreeBSD installed that will burn the FreeBSD image, connect the RPI4 through serial console or SSH; you can also do this on a Windows machine if you know what tools to use
2 Burn the FreeBSD image
Following the guidance of the official document1, FreeBSD 13.2-RELEASE is what we need for the build system. Note that the required FreeBSD version may change with the updates of the OPNsense version.
Plug the storage device into your master machine, change the sdx
to the device name of the storage device, and run the following command to burn the FreeBSD image to the storage device:
|
|
Then, mount the boot partition of the storage device and edit the config.txt
file to enable the serial console:
|
|
And also, overclock the RPI4 (decent cooling is essential if you are doing this):
|
|
Then umount the boot partition:
|
|
You could plug out the storage device now.
3 Boot and set up the FreeBSD system
Now, plug the storage device in your RPI4 and the USB to tty cable to the RPI4 and your master machine2. You can now connect to the serial console through the tty cable. You can use minicom
or screen
on Linux or PuTTY on Windows. And remember to connect the RPI4 to your router or switch. Finally, power it on, and the outputs will shown on the serial console.
|
|
The default passwords are root/root and freebsd/freebsd. Here, we will use the root account to log in and set up the system.
|
|
And get the IP address of the RPI4:
|
|
4 Prepare the building environment
Now, we can abandon the not-so-user-friendly serial console and switch to SSH instead.
|
|
Here, we continue to prepare the building environments.
|
|
5 Build OPNsense
Now, we are all ready to build!
First, build ARM64 common targets step by step.
|
|
Before building the ’ ports ’ target, you can also fetch all the distfiles. It will consequently create a tar file of around 30G, which will be extracted during the following steps, thus requiring an extra 60G free space.
|
|
And after packages
target is built, we can now build system images:
|
|
You can also change DEVICE
from RPI
to other ARM64 machines listed under /usr/tools/device/
; remember to install PRODUCT_WANTS
packages in the config file before build.
Finally, we get our sets and images:
|
|
6 Tricks to accelerate the build
The build process may take over 2 days. And here are some tricks for you to accelerate the whole process.
- Use a faster storage device
The need for more storage speed is the main bottleneck of the build process. You can use an SSD drive with a USB3.0 to SATA adapter.
- Use a good heatsink and overclock the RPI4
The four Cortex-A72 cores of RPI4 are relatively poor in terms of heavy compiling work. Overclocking the RPI4 to 2.0GHz can help a little. And a suitable heatsink is also essential to keep the system stable.
- Use
screen
command
The whole process takes a long time. Therefore, you may need to use the screen
command to keep the build process running even if you are disconnected from the SSH session.
- Reduce workload by deleting ports and packages.
The packages that need to be built are configured in the /usr/tools/config/24.1/
directory, mainly in ports.conf
and plugins.conf
. You can delete the ports and packages you don’t need to reduce the total workload.
- Try an ARM64 machine, which has better performance than RPI4
If you have a powerful ARM64 machine, like a RK3588 board, you can use it to build the image. Although FreeBSD may not be installed on the bare machine, you can still use a KVM virtual machine to run the FreeBSD building environment. And it will be much, much faster.
Related Content
Crowdfunding a new SBC, or just buy me a cpu of coffe.
Sponsor