Do you have an old Pi lying around gathering dust, maybe after a recent Pi upgrade? Are you curious about BSD UNIX? If you answered "yes" to both of these questions, you will be pleased to know that the first is the solution to the second, because you can run NetBSD on a Raspberry Pi as far back as the very first release. In case you're not familiar with BSD, it's the Berkley Software Distribution of [UNIX](#). In fact, it's the only open source UNIX with direct lineage back to the original source code written by Dennis Ritchie and Ken Thompson at Bell Labs. Other modern Unices are either proprietary (such as AIX and Solaris) or clever reimplementations (such as Minix, GNU, Linux). If you're used to Linux, you'll feel mostly right at home with BSD, but there are plenty of new commands and conventions to discover. If you're still relatively new to open source, then trying BSD is a good way to experience a traditional UNIX. Admittedly, NetBSD isn't an OS perfectly suited for the Pi. It's a minimal install compared to many Linux distributions designed specifically for the Pi, and not all components of the recent Pi models are functional under NetBSD yet. However, it's arguably an ideal OS for the older models, since it's lightweight and lovingly maintained. And if nothing else, it's a lot of fun for any die-hard UNIX geek to experience another side of the POSIX world. Download NetBSD {#image} =============== Like Linux, there are different distributions of BSD. With a website featuring the tagline "Of course it runs NetBSD", [NetBSD](#) has cultivated a reputation for being lightweight and versatile. They offer an image of the latest version of their OS for every version of the Raspberry Pi since the original. To download a version for your Pi, you must first [determine what variant of the ARM architecture your Pi uses](#). Some information about this is available on the NetBSD site itself, but for a comprehensive overview, you can also refer to [elinux.org/RPi\_HardwareHistory](#). The Pi I used for this article is, as far as I can tell, a Raspberry Pi Model B Rev 2.0 (2 USB ports and no mounting holes). According to the [Raspberry Pi FAQ](#), this means the architecture is ARMv6, which translates to earmv6hf, in NetBSD's architecture notation. ![My NetBSD Pi](pi.jpg) If you're not sure what kind of Pi you have, the good news is that there are only two Pi images, so try earmv7hf first and if it doesn't work then fall back to earmv6hf. For the easiest and quickest install, use the binary image rather than an installer. Using the image is the most common method of getting an OS onto your Pi: you copy the image to your SD card, and then boot. There's no install necessary, because the image is a generic installation of the OS and you've just copied it, bit for bit, onto the media that the Pi uses as its boot drive. The image files are found in the `binary` > `gzimg` directories of the NetBSD installation media server, which you can reach from the front page of NetBSD.org. The image itself is `rpi.img.gz`, a compressed `.img` file. Download it to your hard drive. Once you have downloaded the entire image, extract it. If you're running Linux, BSD, or Mac OS, you can use the `gunzip` command: $ gunzip ~/Downloads/rpi.img.gz If you're working on Windows, you can install the open source [7zip archive](#) utility. Once the image file is uncompressed, you must copy it to your Pi's SD card. There are two ways to do this, so use the one that works best for you. Using Etcher {#image-app} ------------ Etcher is a cross-platform application specifically designed to copy OS images to USB drives and SD cards. Download it from [etcher.io](#) and launch it. In the Etcher interface, select the image file on your hard drive, then the SD card you want to flash, and then click the Flash button. ![Etcher image flasher](etcher.png) That's it. Using the dd command {#image-command} -------------------- On Linux, BSD, or Mac OS, you can use the `dd` command to copy the image to your SD card. 1. First, insert your SD card into a card reader. Don't mount the card to your system, because `dd` needs the device to be disengaged in order to copy data onto it. 2. Run `dmesg | tail` to find out where the card is located without it being mounted. On Mac OS, use `diskutil list`. 3. Copy the image file to the SD card. Before doing this, you *must be sure* you have the correct location of the SD card. If you copy the image file to the incorrect device, you could lose date. If you are at all unsure about this, use Etcher instead! $ sudo dd if=~/Downloads/rpi.img of=/dev/mmcblk0 bs=2M status=progress When either `dd` or Etcher has written the image to the SD card, place the card in you Pi and power it on. First boot {#boot} ========== The first time it's booted, NetBSD detects that the file system on the SD card does not occupy all of the free space available on it, and resizes the file system accordingly. ![First boot](boot.png) Once that's finished, the Pi reboots and presents you with a login prompt. Log in to your NetBSD system using root as the user name. No password is required. Setting up a user account {#user} ========================= First, set a password for the root user: # passwd Then create a user account for yourself with the `-m` option to prompt NetBSD to create a home directory for you, and the `-G wheel` option to add your account to the wheel group so you have the ability to become the administrative user (root) as needed. # useradd -m -G wheel seth Use the `passwd` command again to set a password for your user account: # passwd seth Log out, and then log back in with your new credentials. Adding software to NetBSD {#software} ========================= If you've ever used a Pi before, then you probably know that you add more software to your system with a special command like `apt` or `dnf` (depending on whether you prefer to run [Raspbian](#) or [Fedberry](#) on your Pi). On NetBSD, you use the `pkg_add` command, but there's some setup required before that command knows where to go to get the packages you tell it to install. There are ready-made (pre-compiled) packages for NetBSD on NetBSD's servers, using the scheme <http://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD///All>. You must replace PORT with the architecture you are using, either earmv6hf or earmv7hf. Replace VERSION with the release of NetBSD you are using; at the time of this writing, that's `8.0`. This value must be placed in a file called `/etc/pkg_install.conf`. Since that's a system file outside your user folder, you must invoke root privileges to create it: $ su - <password> # echo "PKG_PATH=ftp://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/earmv6hf/8.0/All/" >> /etc/pkg_install.conf Now you can install packages from the NetBSD software distribution. A good first candidate is Bash, commonly the default shell on a Linux (and Mac) system. Also, if you're not a user of the `vi` text editor, something more intuitive such as [jove](#) or `nano` is useful to have: # pkg_add -v bash jove nano # exit $ Unlike many Linux distributions ([Slackware](#) being a notable exception), NetBSD does very configuration on your behalf, and this is considered a feature. So to use Bash or `jove` or `nano` as your default toolset, you must set do the configuration yourself. You can set many of your preferences yourself, dynamically, using environment variables, which are special variables that your whole system can access. For instance, most applications in UNIX know that if there is a `VISUAL` or `EDITOR` variable set, then the value of those variables should be used as the default text editor. You can set these two variables temporarily, just for your current login session: $ export EDITOR=nano # export VISUAL=nano Or you can make them permanent by adding them to your `.profile` file: $ sed -i 's/EDITOR=vi/EDITOR=nano/' ~/.profile Load your new settings: $ . ~/.profile To make Bash your default shell, use the `chsh` (change shell) command, which now loads into your preferred editor. Before running `chsh`, though, make sure you know where Bash is located: $ which bash /usr/pkg/bin/bash Set the value for `shell` in the `chsh` entry to `/usr/pkg/bin/bash` and then save the document. Adding sudo {#sudo} =========== The `pkg_add` command is a privileged command, so whenever you use it, you must become the root user with the `su` command. If you prefer, you can also set up the `sudo` command, which allows certain users to use their own password to execute administrative tasks. First, install it: # pkg_add -v sudo And then use the `visudo` command to edit its configuration file. You must use the `visudo` command to edit the `sudo` configuration, and it must be run as root. $ su # SUDO_EDITOR=nano visudo Once you are in the editor, find the line allowing members of the wheel group to execute any command, and uncomment it (remove the `#` form the beginning of the line): ## Uncomment to allow members of group wheel to execute any command %wheel ALL=(ALL) ALL Save the document as described in the bottom menu panel of `nano`, and then exit the root shell. Now you can use `pkg_add` with `sudo` instead of becoming root: $ sudo pkg_add -v fluxbox Net Gain {#end} ======== NetBSD is a full-featured UNIX operating system, and now that you have it set up on your Pi, you can explore every nook and cranny of it. It happens to be a pretty lightweight OS, so even an old Pi with a 700mHz processor and 256 GB of RAM can run it with ease. If this article has sparked your interest and you have an old Pi sitting in a drawer somewhere, try it out!