Skip to content

Instantly share code, notes, and snippets.

@yarwelp
Last active January 30, 2023 11:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yarwelp/3cae5db566f643437fa2 to your computer and use it in GitHub Desktop.
Save yarwelp/3cae5db566f643437fa2 to your computer and use it in GitHub Desktop.
Running FreeBSD on the Raspberry Pi Model B
DocumentID CollectionID
5dde6ac2-0aa4-4d4c-ad5d-691f8addd590
26dee234-2c01-42a8-87f1-4b768887f637

Initial Setup of FreeBSD 10.2

The FreeBSD 10.2 images for Raspberry Pi Model B are available from ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/arm/armv6/ISO-IMAGES/10.2/

From another computer, download the SD image file and put it on the SD card. Example using Ubuntu:

cd ~/Downloads/
wget \
  ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/arm/armv6/ISO-IMAGES/10.2/CHECKSUM.SHA256-FreeBSD-10.2-STABLE-arm-armv6-RPI-B-20151229-r292855 \
  ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/arm/armv6/ISO-IMAGES/10.2/FreeBSD-10.2-STABLE-arm-armv6-RPI-B-20151229-r292855.img.xz
sha256sum -c CHECKSUM.SHA256-FreeBSD-10.2-STABLE-arm-armv6-RPI-B-20151229-r292855 && \
xzcat --verbose FreeBSD-10.2-STABLE-arm-armv6-RPI-B-20151229-r292855.img.xz | sudo dd bs=4M of=/dev/xxx

Replace /dev/xxx above with the device path of your SD card. On Linux, the lsblk command may help you identify the device path of your SD card. Once dd has completed, eject the SD card and remove it from your computer.

Insert network cable and SD card into Raspberry Pi, hook it up to a monitor with HDMI and plug in the power cable of the Pi.

Default usernames and passwords:

  • root/root
  • freebsd/freebsd

Log in as root on the console.

Networking and Services

Where I live, me and the other tennants share a common internet connection through a WiFi router in the living room. The distance from that router to my own room is greater than the longest ethernet cable I have, so I have my main computer -- an ODROID XU-3 single-board computer -- connect via WiFi using a Blueway BT-N9500 18dBi USB-connected antenna.

The WiFi router place us behind a NAT as is common among Norwegian ISPs. We have IPv4 but no IPv6 connectivity.

The ethernet port of my ODROID is connected to a generic 8-port gigabit dumb-switch I bought on eBay, which has model number TH-1008G but no distinguishable brand, though it does also say Tian Hao Wang Luo on the box. To the same switch, I have connected the Raspberry Pi. The Raspberry Pi Model B onboard ethernet port is attached via the USB 2.0 bus and as such supports 100M only. This in turn makes the switch I am using carry all traffic across every port at 100M only, but I'm fine with that.

My ODROID is running Lubuntu 14.04.3 LTS. Using the nm-applet GNOME front-end to NetworkManager, I have configured IPv4 network sharing. This effectively means that the Raspberry Pi resides behind double NAT. In general, NAT is not something I am much of a fan of, but for now it doesn't matter all that much.

I like to turn off my main computer when I'm not using it. If I'd left the FreeBSD default of using DHCP, I'd be seeing spurrious failures to connect from the ODROID to the Pi after having turned the ODROID back on, due to the DHCP lease of the Pi having expired while the ODROID was off and not having been renewed since the ODROID came back up. Rather than mucking about with DHCP, which makes little sense for such a small network, I opt to assign a static IP address to the Pi and tell it what the default route is. Furthermore, rather than setting up a name server for my network, I just maintain the /etc/hosts files on the ODROID and on the Pi.

Using the text editor vi, I edit /etc/rc.conf on the Pi to hold the following:

hostname="rpi-b"

#ifconfig_DEFAULT="DHCP"
ifconfig_ue0="inet 10.42.0.47 netmask 255.255.255.0"
defaultrouter="10.42.0.1"

sshd_enable="YES"
sendmail_enable="NONE"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
#ntpd_enable="YES"
ntpdate_enable="YES"

#growfs_enable="YES"

In addition to having set a static IP and a default route, I also asked to enable ntpd(8). This because the Raspberry Pi Model B does not have a Real-Time Clock (RTC), so every time it boots, the correct time must be set. ntpd takes care of that by querrying a set of time-servers online. ntpd could also be used as a time server for other computers on the local network but I do not have any need for that. It used to be that one would enable the ntpdate(8) daemon if one wanted to be a client only but according to the man page of ntpdate(8), ntpdate is to be retired from FreeBSD now that the functionality is avilable in ntpd. However, that alone did not set my clock right so for now I'll be using ntpdate.

In order to apply these specific changes without reboot, we run the following commands:

/etc/rc.d/netif restart
/etc/rc.d/ntpd start

Building and Installing Packages

TODO: Rewrite this section to build packages on the Raspberry Pi using Poudriere.

Packages are not available for FreeBSD on Raspberry Pi, so ports must be built from source.

This can be done either of the two following ways:

  • Preferably cross-compiling from a more powerful computer, using Poudriere and QEMU, or
  • The eternally slow way by building them on the Pi itself, as described below.

The default tmpfs configuration included in the image of FreeBSD 10.2 for the Raspberry Pi Model B is too small to hold intermediate files generated during certain builds (e.g. that of the devel/llvm36 port). Perhaps a bigger size could be found which would allow the builds to be performed but also without the tmpfs eating too much RAM? I opt to unmount the tmpfs and outcomment the /etc/fstab line for it, taking the performance hit writing to the SD instead of in RAM might introduce in trade for not having future builds fail randomly because some intermediate file of some port was suddenly larger than anticipated. I might later want to have my SD card mounted read-only in order to reduce wear but since mounting the SD read-only would lead to a bunch of other things needing to be configured accordingly anyway, for now we'll do like this.

umount /tmp
sed -i -e 's/^tmpfs/#&/' /etc/fstab

Fetch ports tree, install portmaster, fetch distfiles, then install core Xorg ports and the suckless surf web browser.

portsnap fetch extract && \
cd /usr/ports/ports-mgmt/portmaster/ && make fetch-recursive install BATCH=yes && \
cd /usr/ports/x11/xorg-minimal/ && make fetch-recursive BATCH=yes && \
cd /usr/ports/x11-drivers/xf86-video-scfb/ && make fetch-recursive BATCH=yes && \
cd /usr/ports/x11/xorg-apps/ && make fetch-recursive BATCH=yes && \
cd /usr/ports/www/surf/ && make fetch-recursive BATCH=yes && \
portmaster -G -D --no-confirm x11/xorg-minimal x11-drivers/xf86-video-scfb x11/xorg-apps www/surf

Wait a million years for compilation of Xorg, surf and dependencies to finish.

To Be Continued.

See Also

https://wiki.freebsd.org/FreeBSD/arm/Raspberry%20Pi

---
CollectionName: Running FreeBSD on the Raspberry Pi Model B
CollectionID: 26dee234-2c01-42a8-87f1-4b768887f637
Documents:
5958232b-13b9-4b43-8428-6e80d0170f81: 00_INDEX.md
5dde6ac2-0aa4-4d4c-ad5d-691f8addd590: 01_INITIAL_SETUP.md
---
Copyright (c) 2016 Erik Nordstrøm <erik@nordstroem.no>
Redistribution and use in source (GitHub Flavored Markdown) and 'compiled'
forms (HTML, PDF and so forth) with or without modification, are permitted
provided that the following conditions are met:
1. Redistributions of source code (GFM) must retain the above copyright
notice, this list of conditions and the following disclaimer as the first
lines of this file unmodified.
2. Redistributions in compiled form (transformed to other formats)
must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS DOCUMENTATION IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS DOCUMENTATION,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment