Installing FreeBSD on Raspberry Pi using Linux

--

Raspberry Pi is a cheap computer that’s perfect for trying FreeBSD without investing too much money (or time in this case since you don’t even have to go through installing it or struggling with device compatibility issues).

Read: Technical reasons to choose FreeBSD over GNU/Linux

In this guide we’ll see how to use a Linux machine to build a bootable disk for FreeBSD. In 10 minutes you’ll boot into FreeBSD console (no GUI). You need:

  • Raspberry Pi (any version)
  • An SD/MicsoSD card (depending on your Raspberry Pi version) with at least 1GB capacity
  • A USB keyboard (mouse not needed)
  • A monitor that supports HDMI
  • A micro USB charger (like the one from your mobile phone)
  • A Linux machine with an Internet connection (download size is around 150MB) and a built-in or external card reader

Identify your Raspberry Pi model

FreeBSD officially supports Raspberry Pi and binary images are available for download. In order to find the right download file, you need to know which Raspberry Pi you have. Here is the official guide.

For example I’m using a 5 year old Raspbery Pi B with 0.5GB RAM and a 4GB SD Transcend SD card using Lubuntu machine.

Download the image

Go to the official FreeBSD download site and download the latest version of the .img.xz file for your Raspberry Pi. Skip the CHECKSOME files and go to the bottom of the page. For me at the time of writing the newest version is: FreeBSD-11.0-STABLE-arm-armv6-RPI-B-20170323-r315855.img.xz

Decompress the image

Decompress the FreeBSD-XXXXXX.img.xz file to get an .img file.

$ unxz path-to-the-downloaded-freebsd.img.xz --verbose

This will replace your .img.xz file with the uncompressed .img file. If you want to keep the compressed downloaded file use the --keep option:

$ unxz path-to-the-downloaded-freebsd.img.xz --verbose --keep

Identify the device name for the SD card

There are many ways to do that. For writing the image, we need a reference to the whole drive (ex. /dev/sdb) not a particular partition on it (ex. /dev/sdb1 or /dev/sdb2).

The easiest way is to run the following command right after you insert the card into the card reader:

$ dmesg | tail

This command gives you the latest kernel message which is sure gonna have something about your SD card insertion event.

On Ubuntu 18.04 I use the Disks application to get the name of the device:

The device name is /dev/mmcblk0

If the SD card is mounted, another way to get a reference is to run:

$ mount | grep '^/dev' 

This will give you all the device files and their corresponding mount points.

Another method is to ask Linux about the device name that is mounted to a particular directory that you know represents your SD card:

$ findmnt -n -o SOURCE --target /path/to/files/on/sdcard

In my case since I had Raspbian on the card and it has made a /boot partition for me, I run this:

$ findmnt -n -o SOURCE --target /media/user/boot

Which gives me /dev/sdb1 so the reference to the SD card is /dev/sdb. And for the sake of documentation one of the coolest solutions is lsblk:

$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 119,2G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 488M 0 part /boot
└─sda3 8:3 0 118,3G 0 part
├─lubuntu--vg-root 252:0 0 112,4G 0 lvm /
└─lubuntu--vg-swap_1 252:1 0 5,9G 0 lvm [SWAP]
sdb 8:16 1 3,7G 0 disk
├─sdb1 8:17 1 56M 0 part /media/user/boot
└─sdb2 8:18 1 3G 0 part /media/user/3d81d9e2-7d1b-4015-8c2c-29ec0875f762

Write the image to the SD card

Note: this stage is very sensitive and may fuck up your system if you pick the wrong device name for the of (output file) option.

dd is a useful Unix command that writes the contents of a file (in this case the downloaded and decompressed image) into a device file (in this case your SD card). It has two options:

  • if: path to the input file
  • of: the device file for the SD card you identified in an earlier step (again, you need a reference to the whole file not just a partition on it)
# dd if=path-to-the-downloaded-freebsd.img of=/dev/YOUR-SDCARD bs=1M status=progress

In my case it is:

# dd if=path-to-the-downloaded-freebsd.img of=/dev/sdb bs=1M status=progress

Note: if you want to do it the other way around (copying from an SD card to a *.img, possibly for cloning an already existing and configured disk) do this:

# dd if=/dev/sdb of=path-to-save-file.img bs=1M status=progress

And finally unmount the disk to put it into Raspberry Pi.

$ umount /dev/YOUR-SDCARD

Boot FreeBSD

  • Connect the HDMI to the monitor
  • Attach the USB keyboard.
  • Put the SD card in place
  • Connect the power.

It’ll show some boot messages and eventually gives you the login prompt (on my Raspberry Pi B it took about a minute).

  • The default username is freebsd and its password is freebsd.
  • The root account is root and its password is root as well.

So the first thing you wanna do after logging in is to change your password as soon as possible:

$ passwd

What’s next?

If you use a non-English keyboard, the first thing you wanna do is to set your keyboard layout:

$ kbdmap

The BSD distributions have a reputation of having excellent documentation.

Checkout the newbie guide on FreeBSD’s website. If you’re using Linux, you want to check out FreeBSD for Linux users. Also if you like a GUI, here is how to set it up.

Bonus: FreeBSD can run Linux programs without having to recompile!

Liked what you read? Follow me to be notified when I write something new.

--

--

Responses (1)