Tuesday, December 16, 2014

FreeBSD on Raspberry Pi B+

It has been almost 10 years since I ran my own UNIX-like server at home. The last Debian machine died because of hardware failures. It was an old Pentium II machine. It started itching again a week ago. I wanted to run a server at home 24/7 at a very low cost. It would also be a great opportunity to refresh my C programming skills again.

I you think about low cost, then Raspberry Pi would undoubtedly come to mind. It's a very small but capable device. The costs of running it 24/7 is about 5 EUR per year. So I looked around online, and finally bought the model B+ with a nice translucent casing, a 1A power adapter, an HDMI cable, and a SanDisk Extreme 16GB MicroSD card. The total costs for the complete server setup: 70 EUR.

Now I had the hardware set. Next, I needed to select a nice OS image to put on the memory card. I narrowed it down to Raspbian, and FreeBSD. Raspbian is based on Debian, which I’m very familiar with. I've been running Debian for years. I really like their packaging system, and the minimal install. But I really wanted something closer to UNIX than Linux, so I went for FreeBSD.

Installation

Lucky me, the latest release supports Raspberry Pi. So I downloaded the image (FreeBSD-10.1-RELEASE-arm-armv6-RPI-B.img) from their site. This is how I put the FreeBSD image on the memory card. I used Mac OS X to do it. On the Mac, I changed to the root user, so I’m allowed to write to a device directly.

sudo su -

(Yes, you can also do "su", but SyntaxHighlighter rendered that command invisible.) Now I needed to determine the name of our memory card device. So I executed the following command, before inserting the memory card.

diskutil list

I memorized the list, and inserted the memory card. Now I executed the previous command again and checked that there is a new device in the list. This would then be my memory card device. On my computer, it was the “/dev/disk1” device. Now I unmounted the file system cleanly with:

diskutil unmountDisk /dev/disk1

Now I wrote the FreeBSD image directly to disk with the next command. Please be careful, and make sure the device is correct. Otherwise you risk damaging the existing file system used by your computer!

dd if=FreeBSD-10.1-RELEASE-arm-armv6-RPI-B.img of=/dev/disk1 bs=1m

After this, I ejected the card:

diskutil eject /dev/disk1

Now I inserted the memory card in the Raspberry Pi, and I connected the HDMI cable to my TV. The moment of truth: connect the USB power supply, and see if it boots!

Unfortunately, my TV screen remained black. So I double checked the cables and screen settings, but to no avail. FreeBSD didn’t boot. After some Google research, I found out there was probably something wrong with the boot/firmware files. So I replaced the following files on my memory card with the files downloaded from: https://github.com/kientzle/crochet-freebsd/tree/master/board/RaspberryPi/boot

  • bootcode.bin
  • fixup.dat
  • fixup_cd.dat
  • start.elf
  • start_cd.elf

That did the trick, Raspberry Pi booted successfully to a FreeBSD login prompt!

Post installation tasks

To be able to be root, I needed to be member of the “wheel” group:

pw user mod gin -G wheel

I also wanted the system date to be automatically synced. So I enabled the time daemon:

tzsetup (set local time zone)
echo 'ntpd_enable="YES"' >> /etc/rc.conf
echo 'ntpd_sync_on_start="YES"' >> /etc/rc.conf
service ntpd start

There are no binary packages available, but there is an alternative called “portsnap”. With portsnap you basically download a directory structure of all packages available. Go into the directory of the port you want, and execute the makefile in the directory to automatically download and install the port.

To install portsnap run:

portsnap fetch
portsnap extract
portsnap fetch
portsnap update

With portsnap I successfully compiled and installed the following programs:

  • screen
  • git
  • subversion
  • wget
  • autoconf
  • automake
  • libtool

References:

5 comments:

  1. This post was the exact explanation detail I need to click my understanding of using FreeBSD crochet and freebsd-src to git compile link my FreeBSD 13.0 Current version in January 2021.
    cd ~
    git clone https://github.com/freebsd/crochet.git
    sudo su -
    cd /usr/src
    git clone https://github.com/freebsd/freebsd-src.git

    https://blog.grem.de/sysadmin/FreeBSD-On-rpi3-With-crochet-2018-10-27-18-00.html

    ReplyDelete
  2. cd ~/crochet
    nano config.sh uncomment which board you wish to build for. The raspberrypi3 will work for the raspberrypi4 SBC
    sudo /bin/sh crochet.sh -c config.sh
    This should build you an FreeBSD 13.0 Current image to burn into a micro SD card for the raspberry pi 4B and other single board computers

    ReplyDelete
  3. That's an impressive setup you've got there! The Raspberry Pi B+ is a great choice for a low-cost server, and coupling it with FreeBSD offers a wonderful chance to dive back into coding while keeping the running costs incredibly low.

    SEO Los Angeles

    ReplyDelete