During our last Sandstorm Retreat there was not a single day without a remote participant. "But how fast and reliable is the internet connection really, in a location we never visited before?", we asked ourselves and decided to pack our Starlink receiver and, just like in the office, implement a network at the location with two independent WAN-connections. To manage these WAN-connections, we packed our office gateway. Thus we had a redundant internet connection at the location and a non-redundant one at our main office… we know our priorities. :-)
As removing the gateway from the networking rack and re-configuring it was quite some effort, we decided to go a different way in the future:
We are building our own 2 WAN gateway on a much smaller, more light-weight and more mobile Banana Pi R2 (BPI-R2 for short). In this blog post I share my experience during the installation of the operating system up to the first successful connection via SSH.
Note that I work on OS X on my MacBook. All shell commands in this blog post are for Macs. They are slightly (Linux) or very (Windows) different on other operating systems.
After checking the Wiki page I started to try out some operating systems. Below I share my experience with
- Opening a TTY console (no HDMI, no SSH)
- Creating a bootable SD card
- How to back up a bootable SD card
- Powering on the BPI-R2 (not as simple as it sounds)
- Bananian Linux
- Alpine Router Platform
- Debian 10
- Ubuntu 16.04.
- Open work (more things to explore)
- Helpful links
Note: I did not go into full-detail for each and every OS. Maybe I'll come back to an open topic later. Then I'll update this blog post.
Opening a TTY console (no HDMI, no SSH)
First things first: How to debug a device without an HDMI driver when it fails booting? You connect via a TTY console. This is a fully operational CLI terminal. To open it, you need to
- fetch your TTY-USB-adpater
- find the TTY pins on the BPI-R2 main board between the SATA ports and the WAN port
- connect the pins to your adapter as follows
- GND - GND
- TXD - RX
- RXD - TX
- connect the USB-adapter to your MacBook and wait for mount
- run screen /dev/$(ls /dev | grep cu.usbserial) 115200
Creating a bootable SD card
How you write an image on the SD card, depends on the image. In the easiest case you can use dd but sometimes you have to adjust details of the command. Sometimes it does not work and it is rather slow. An alternative is an app called balenaEtcher. I started using the app instead of dd.
How to back up a bootable SD card
To be fair: so far I did not need to recover an SD card from a backup. It should work in theory.
For more details read Backup your Raspberry Pi: How to Save and Restore Files (3 Methods).
Powering on the BPI-R2 (not as simple as it sounds)
Ironically I had some trouble turning on the BPI-R2. Execute the following steps and it might work. I explain after the list what can go wrong in which step.
- insert the SD card
- move little switch over the SD card slot to "SD"
- insert power supply
- press the PWR button
Sounds simple enough, but you should know the following.
- (step 2) the switch has no effect in some cases, it also depends on the (pre?) bootloader on the SD card
- (step 3) make sure that the plug sits firmly and that the inner diameter is not too wide (yes, this took me some time)
- (step 3) do not touch the board, you might shortcut something and leave the board in an error-state
- (step 4) hold the PWR button for 5 to 10 seconds or the BPI shuts down
- (step 4) it always shuts down when there are issues with the SD card
- (step 4) … and you might see nothing on the TTY terminal
There is a dedicated forum thread for switching on the BPI-R2.
On bananian.org/download I found the following statement dated April 2017.
The image actually did not start to boot. Maybe I made a mistake writing the image to the SD card with dd. Maybe it would have worked using Etcher.
Since I want to configure a router, OpenWrt looks like a perfect match. There is a nice documentation and a multi-WAN extension. It has a downside though: no support for HDMI and WiFi. HDMI is not supported in most operating systems for the BPI-R2 and luckily we do not need it. WiFi on the other hand… We want to use the self-built router in a remote location. Usually we bring our own access points, but if one WAN-Uplink is only available via WiFi, it would be nice to use the WiFi as a WAN port.
I gave it a try. Two versions seemed to support the BPI-R2. I calculated the SHA-256 hashes myself after the download, so no guarantee on that.
- 19.07.7 (SHA256 59097804f1543087466ce2540e656bf639899ddb84171a923a9e60bb954888a3)
- 19.07.8 (SHA-256 8ae12c5593faffb076db2ccb6309f6ffc1ba973ff7edb424dd5025562d1f6979)
Version 19.07.7 started to boot but produced errors visible in the TTY console. Version 19.07.8 did not boot. Again: I did not (yet) try to write the 19.07.8 image to the SD card using Etcher instead of dd. Here are the two links which helped me the most:
Alpine Router Platform
The latest version with a ready-to-use SD card image for the BPI-R2 I found was from 2018-06-16. This one is 8GB in size. There are smaller images available. According to the documentation you can login via SSH as root:pantacor and have to find the IP address in the DHCP lease of the BPI on your DHCP server.
I found an SD card image in a public Google Drive (thanks a million) as advertised on the BPI-R2 wiki page. The MD5 hash is in the drive, I calculated the SHA256 as 251b3ac7da22c20bc8aa4fd16d38c08e4984d009b8b328af08e25e625caf5595. According to the Wiki it supports Wifi and SATA (I did not test either one yet). The TTY console and SSH work out-of-the-box. You can login as root/bananapi at 192.168.0.11 on LAN port 0 (the one next to the WAN port). HDMI is not supported.
Most likely we stay with this operating system for our project.
Most likely we stay with Debian 10 for our project.
The BPI-R2 wiki page promotes Ubuntu 16.04. but there is no SD card image available for download. You have to create it yourself. This took me the most time by far (due to lack of experience with manually creating bootable devices). Hence this part is rather long and verbose – written from a beginners perspective.
Eventually I created a booting SD card. There have been kernel modules which did not load (got errors in the TTY console) but still… it did boot. I did not spend time fixing those errors since I just wanted to create the SD card. Fixing a broken operating system was out-of-scope for me. Nonetheless here come the steps I took:
Create a VM with Ubuntu 16.04.
On my local machine I use VirtualBox whenever I need a VM. You will find a lot of tutorials online explaining how to install Ubuntu in VirtualBox. I like to use a bridged network for the VM and connect via SSH. Just as if I would connect to a remote server.
Since the advertised download page no longer exists, you need to create your own SD card image. The first step is to build the project. Once you have a working terminal open, type in the following commands.
Create an SD card image
The documentation of BPI-R2-bsp-4.14 does not cover the creation of an SD card image. You cannot just dd one of the many build artifacts onto an SD card though. I found this very helpful forum post: How to build an Ubuntu/Debian SD image from scratch. I'll got through the commands here and add some more explanation.
Next we want to install an operating system and a boot sector into this empty file. First mount the empty file as "a disk". This makes working with the file easier. Especially since we need to create partitions.
Now we can treat /dev/loop8 as a disk and create disk partitions with the required file systems.
Now that we formatted the partitions, we want to write to them. So let's mount the partitions.
Now everything is set up and we can install a minimal Debian system on the new partition.
The next step excited me the most. We switch the operating system from our current VM to the SD card. This is what I usually do to recover a damaged operating system after booting from a CD or a USB stick.
To be clear:
- We are on your working machine inside a VM
- with a file mounted as a disk with a partition on it
- which we now use as our new root directory.
Now we can complete the Debian setup and configure our system.
We leave our soon-to-be SD card operating system and switch back to the VM Ubuntu 16.04 installation.
With the base operating system in place, we still have to do something with our self-compiled artifacts. Let's copy some files to the still mounted partitions before ejecting them.
No, not done yet.
We cannot directly boot our final operating system. Some steps must happen before, to enable more features, e.g. access to more board components or access to a fat16 file-system… features we need to even start booting Ubuntu.
Remember that we left the first part of the card image empty? The first partition starts at 100MiB. Now we write into this empty space. We use dd to transfer bytes directly into our image file, which is still mounted as a disk.
Finally – the image is ready. Time to fetch it from the VM and write it to an actual SD card.
Since I have been too lazy to make the physical SD card accessible in my Ubuntu VM, I have to copy the image file to my MacBook.
You can write the zipped image file to the SD card using Etcher now.
As mentioned, the resulting Ubuntu SD card boots with some errors. TTY works but network is down. I did not find time yet to analyze or fix the error. I can access the system via the TTY console and get the following error message:
Open work (more things to explore)
First: configure the installed Debian 10 to use two ports as WAN ports.
Further things I would like to look into:
- it would be nice to fix the Ubuntu image
- some SD card did not boot after writing the image with dd
- test these images again with Etcher
I added all links which I considered helpful into the post above. Of course, there is much, much more to explore. Here are some additional related links I found while searching the web. A huge thanks to everyone who shares his/her experience!!!
- BPI-R2 board layout explained
- Raspbian For Banana Pi (from 2014)
- Busybox for BPI
- later version on OpenWrt (without support for BPI-R2?)
- About banana pi BPI-R2
- How to Configure and use Linux as a Router
- How To Configure Linux as a Static Router
- How to Turn a Linux Server into a Router to Handle Traffic Statically and Dynamically – Part 10
Thanks for reading
Thank you a lot for reading this huge post. As always, feedback is very welcome. Please get in touch.