Archives

All posts for the month January, 2016

After upgrading one of my Kodi media center boxes from a Raspberry Pi B+ to a Raspberry Pi 2, I decided to play with NetBSD on the old Pi B+. Installing NetBSD is a simple process and the install docs cover it well, but here are a few notes that might be useful for completing your post-install configuration. The NetBSD documentation should be your first resource, of course; this just covers a few Pi-specific things I found relevant.

Since the install process is really just writing a disk image to the MicroSD card and then booting the system, you’ll have to manually complete a number of configuration steps that would usually be handled by the installer. Fortunately, it’s pretty straightforward.

First Boot

Expect the first boot to take some time. The system will resize the / partition to use all available space on the MicroSD card (more on this later) and generate SSH host keys. This will not be fast.

You’ll eventually get a login prompt. root has a blank password by default. Hostname will be rpi. The DHCP client is active by default, so you may have a working network connection.

Network Configuration

I wanted a static IP address, so I created /etc/ifconfig.usmc0 with the contents:

inet 192.168.1.25 netmask 255.255.255.0

I also defined my DNS nameserver in /etc/resolv.conf:

domain irascible.net
nameserver 192.168.1.1

NetBSD uses the /etc/rc.conf file as the main system-wide configuration file. The following changes are all made to that file.

I defined my hostname and default route, and disabled the DHCP client:

hostname=raspberrypi.irascible.net
dhcpcd=NO
defaultroute=192.168.1.1

Time Configuration

The Pi has no real-time clock, so you’ll want to use ntpdate to set the clock at boot. The -b option jumps the clock to the correct time, rather than trying to correct it by slewing. I also chose to enable ntpd to keep the clock synched:

ntpdate=YES
ntpdate_flags=”-b”
ntpd=YES

The system will be using UTC time by default. Set it to your preferred timezone instead:

ln -fs /usr/share/zoneinfo/Your/Zone /etc/localtime

It’s not gonna get any bigger!

After the first boot, there’s no need to try to resize the disklabel and root partition on every reboot, so those options can be turned off:

resize_disklabel=NO
resize_root=NO

Enabling PF

NetBSD includes a (rather outdated) version of OpenBSD’s excellent pf firewall, which I wanted to use. Note you’ll also need an appropriate pf.conf file. To enable pf and the pf logging daemon:

pf=YES
pflogd=YES

pkgsrc Configuration

NetBSD uses pkgsrc for package management. Somewhat confusingly, you don’t actually set your $PKG_PATH variable in /etc/pkgpath.conf; it goes in /etc/pkg_install.conf instead:

PKG_PATH=http://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/earmv6hf/7.0_2015Q3/All/

You can then pkg_add to your heart’s content. Note that pkgsrc does quarterly releases of binary packages, so the 7.0_2015Q3 portion may need to be updated.

More Power! More memory!

The Raspberry Pi doesn’t have anything like a BIOS interface for setting low-level hardware configuration options. Instead, you can edit the /boot/config.txt file to make changes. On my system, I’m doing a moderate overclock to extract a bit more performance from the anemic hardware. Obviously, do this at your own risk; my Pi has added heatsinks and has been perfectly stable with this mild overclock.

By default, 64 MB of memory will be allocated to the GPU. If you’re planning to run your Pi headless, there’s no reason to dedicate unneeded memory to graphics, so you can crank that down to 16 MB:

arm_freq=800
core_freq=300
sdram_freq=400
over_voltage=0
gpu_mem=16

Unresolved Issues

As mentioned earlier, the first boot process will resize the / partition to use all available space on your MicroSD card. I’m not a huge fan of this, since I really like having at least /var and /tmp on their own partitions. A reasonable approach would seem to be: shrinking the filesystem on /dev/ld0a using resize_ffs, updating the disklabel to match, then adding new partitions and filesystems as desired.

I haven’t actually been able to accomplish this yet due to issues with resize_ffs. I’m using a 32 GB SD card with my Pi, which results in a / partition of 28 GB. If I boot single-user and try to shrink the root partition with resize_ffs, I get the error:

resize_ffs: Can’t map 1936261120 bytes for inodes: Cannot allocate memory

resize_ffs is trying to grab 2 GB of memory on a box with 512 MB total, which obviously isn’t going to fly. I’ll have to circle back to this. I think a better approach would be updating the disk image to NOT resize on first boot.