I started getting into BSDs (specifically NetBSD) as a result of my membership in SDF. I have a good deal of Linux experience but hadn’t really had a good reason to try out one of the BSD operating systems. I remembered I had a first-gen Raspberry Pi (Model B) languishing in my desk drawer and decided to put NetBSD’s slogan (“Of course it runs NetBSD!”) to the test.
The Model B features a 32-bit armv6 chip and 256MB of RAM (!). I poked around on the NetBSD homepage and found this page which told me “earmv6hf” was the NetBSD port I wanted for an rpi 1.
This article on opensource.com does a fantastic job of showing the initial steps to get it running, and I won’t attempt to reproduce those here. Instead, I want to fill in some gaps.
So you’ve followed the opensource.com article above and you’re sitting at a root prompt with your Pi hooked up to a TV and a keyboard plugged into one of the two USB ports. Now, you want to be able to use the Pi as a “server” and stash it somewhere. Unfortunately, Pis this old don’t have onboard WiFi, so you’ll need an adapter. This is one area where NetBSD is a bit rough around the edges: the WiFi adapter support isn’t as strong as some Linux distributions. Even if your Pi has onboard WiFi, it is unlikely that NetBSD supports it.
I used this adapter and I know that it works out of the box with NetBSD 8.0. If that Amazon link ever dies, the adapter is the Edimax EW-7811Un. Be aware that this adapter does not have dual-band support, so you’ll have to stick with 802.11n. This means you can’t use the 5GHz band of your router.
Once you have the adapter, shut down the pi at the root prompt with shutdown -p now
. You’ll eventually see a message saying “press any key to restart”. Once you see this, unplug the Pi. Now, plug in the Edimax adapter to the empty USB port and reconnect the Pi. When you’re back at your root prompt, follow the instructions here to set up wpasupplicant, which is the NetBSD daemon that handles WPA/WPA2. I was able to copy/paste the “simple” example from the wpasupplicant page:
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=wheel
network={
ssid="my favourite network"
psk="hunter2"
}
I replaced the ssid and psk with my network’s info. The tutorial tells you to edit /etc/rc.conf and add the following lines:
wpa_supplicant=YES
wpa_supplicant_flags="-i iwn0 -c /etc/wpa_supplicant.conf"
iwn0
is a network interface - find yours by typing ifconfig
and looking for interface name whose address starts with 74:da:38
(provided you’re using my recommended adapter). Mine is urtwn0
, so I replaced iwn0
in the above command with urtwn0
. Now you should be able to find the Pi on your network and SSH into it - no need for the TV anymore!
After enabling bash as my shell per the opensource.com guide, I found that some things were not on my $PATH by default. I loaded a custom .bashrc file to get my normal aliases, and found that “pkgadd” was no longer on the PATH. Also, it seems that no .bashprofile is created by default in your user’s home directory. To fix both these issues, add the below lines to the newly-created ~/.bash_profile:
PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R7/bin:/usr/pkg/bin
PATH=${PATH}:/usr/pkg/sbin:/usr/games:/usr/local/bin:/usr/local/sbin
source .bashrc
The opensource.com guide talks about pkgsrc, which allows for the installation of both binary and source packages for NetBSD. If you’re coming from Linux though, you’re probably expecting something that works like yum or apt. pkgsrc does not work this way and crucially, it doesn’t have a great story for updates. Pkgin is what you’re looking for here. Run pkg_add -v pkgin
as root and then follow the guides on the pkgin homepage from there. Pkgin uses pkgsrc under the hood. Remember that your old Pi 1 is very underpowered, so expect package installations to take a while.
After you’ve installed pkgin, there will be a message telling you to run pkgin update
. Before you do this, check the file in /usr/pkg/etc/pkgin/repositories.conf. The url in there was wrong by default on my installation. For an rpi 1, it should be ftp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/earmv6hf/8.0/All
. Once that’s correct, run pkgin update
.
Never unplug the Pi without running shutdown -p now
first and waiting a bit if you’re doing that over SSH. The older models seem especially sensitive to corruption of the SD card. If this happens to you, you’ll have to hook your Pi up to a TV again and single-user mode will be active. From there you can use fsck -tufs -y /dev/<your sd card>
You can typically find your sdcard name by running fdisk
. In many scenarios this will repair your disk. If it fails for some reason, well, GOTO the top of this guide and reimage.
Many of the tools you’re used to having out of the box in Linux distributions will not be installed. NetBSD is highly configurable and does not attempt to decide what you should use. Most things will be easily available on pkgin though.
Now you can install the packages you’re used to, like vim, git, etc. Happy hacking!
I hope you’ve enjoyed this post. Hit me up on Mastodon with any questions or comments!