Recently I purchased myself a new and shiny RaspberryPi for use on my home network as a dedicated play ground. Having never played with one before, I decided to try out the standard images available from the official RaspberryPi website. I tried a couple of flavours like ArchLinux and Raspbian but as a FreeBSD enthusiast, I decided to use this opportunity to see how it ran on the ARM architecture.
There are two methods of doing this; For this post, I’ll discuss the easy method. I’ll create a second post detailing how to build from source as there is a little more involved.
(1) The Easy Method
FreeBSD now produce ARM builds which are supported by a number of boards, including RaspberryPi which are available for download from their site. It’s possible to download the images, mount them and make any required changes to customise it to your liking before writing it to your SD card and booting on your RPi. Handy out!
(2) Build a custom version from source
This is a little more advanced, but allows for greater flexibility. This method allows you produce your own image using a custom kernel.
The Easy Method
Firstly, navigate to FreeBSD’s site, and download a copy of the latest build. At the time of writing, FreeBSD produce an image for 10-STABLE and 11-CURRENT. I went with 10-STABLE in the end as I had problems booting 11-CURRENT. Next, I’d detail how to mount the image and make some basic changes such as enabling SSH, DHCP etc and creating a standard user account for remote access, along with some basic config tips.
At home, I tend to use a Macbook Pro. For this, I downloaded FreeBSD (x86) ISO and installed it into a VM (VirtualBox). I did this mainly for two reasons; 1 to utilise FreeBSD tools to make the changes required and 2, so I could attempt to build from source using the FreeBSD ARM tool-chain. After you have FreeBSD set up in VirtualBox, proceed with the following steps:
1. Download the RPi image
I ended up going with 10-STABLE for this and it seems to be working out pretty well thus far. Firstly, navigate to the FreeBSD RPI public FTP drop site and download the latest image.
[alan@virtualbox ~]$ wget ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/arm/armv6/ISO-IMAGES/10.0/FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img.bz2
--2014-06-18 10:09:17-- ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/arm/armv6/ISO-IMAGES/10.0/FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img.bz2
=> 'FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img.bz2'
Resolving ftp.freebsd.org (ftp.freebsd.org)... 193.162.146.4, 2001:6c8:130:800::4
Connecting to ftp.freebsd.org (ftp.freebsd.org)|193.162.146.4|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /pub/FreeBSD/snapshots/arm/armv6/ISO-IMAGES/10.0 ... done.
==> SIZE FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img.bz2 ... 129022750
==> PASV ... done. ==> RETR FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img.bz2 ... done.
Length: 129022750 (123M) (unauthoritative)
100%[===========================================================================================================================================================================================>] 129,022,750 386KB/s in 5m 49s
2014-06-18 10:15:07 (361 KB/s) – ‘FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img.bz2’ saved [129022750]
[alan@virtualbox ~]$ md5 FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img.bz2
MD5 (FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img.bz2) = 996fa40f1331297f36e0a94cecb7a7a6
[alan@virtualbox ~]$ bunzip2 -d FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img.bz2
[alan@virtualbox ~]$ ls -al FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img
-rw-r–r– 1 alan alan 1000000000 Jun 18 10:15 FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img
[alan@virtualbox ~]$
2. Mount the image
Next, we’ll mount the image. There are two partitions within this image. The boot partition which contains the uboot binary and configuration (FAT32 partition) and the system base (UFS partition). We’ll only need to mount the systme base to make our own changes. In order to do this, perform the following:
[alan@virtualbox ~]$ mv FreeBSD-10.0-STABLE-arm-armv6-RPI-B-20140608-r267232.img rpi.img
[alan@virtualbox ~]$ su
Password:
root@virtualbox:/home/alan # mkdir -p /mnt/rpi
root@virtualbox:/home/alan # mdconfig -a -f rpi.img
md3
root@virtualbox:/home/alan # mount /dev/md3s2 /mnt/rpi
root@virtualbox:/home/alan # ls -al /mnt/rpi
total 4216
drwxr-xr-x 18 root wheel 1024 Jun 9 10:27 .
drwxr-xr-x 3 root wheel 512 Jun 18 10:29 ..
-rw-r--r-- 2 root wheel 964 Jun 9 10:50 .cshrc
-rw-r--r-- 2 root wheel 252 Jun 9 10:50 .profile
drwxrwxr-x 2 root operator 512 Jun 9 10:49 .snap
-r-------- 1 root wheel 4194304 Jun 9 10:49 .sujournal
-r--r--r-- 1 root wheel 6196 Jun 9 10:50 COPYRIGHT
drwxr-xr-x 2 root wheel 1024 Jun 9 10:49 bin
drwxr-xr-x 8 root wheel 1024 Jun 9 10:50 boot
dr-xr-xr-x 2 root wheel 512 Jun 9 10:49 dev
drwxr-xr-x 22 root wheel 2048 Jun 9 10:50 etc
drwxr-xr-x 3 root wheel 1536 Jun 9 10:50 lib
drwxr-xr-x 3 root wheel 512 Jun 9 10:49 libexec
drwxr-xr-x 2 root wheel 512 Jun 9 10:49 media
drwxr-xr-x 2 root wheel 512 Jun 9 10:49 mnt
dr-xr-xr-x 2 root wheel 512 Jun 9 10:49 proc
drwxr-xr-x 2 root wheel 2560 Jun 9 10:49 rescue
drwxr-xr-x 2 root wheel 512 Jun 9 10:50 root
drwxr-xr-x 2 root wheel 2560 Jun 9 10:50 sbin
lrwxr-xr-x 1 root wheel 11 Jun 9 10:50 sys -> usr/src/sys
drwxrwxrwt 2 root wheel 512 Jun 9 10:49 tmp
drwxr-xr-x 14 root wheel 512 Jun 9 10:49 usr
drwxr-xr-x 24 root wheel 512 Jun 9 10:49 var
root@virtualbox:/home/alan #
3. Create standard user – pi
Next, we’ll create a standard user called ‘pi’ using the password ‘raspberry’. This will enable you to login remotely over SSH after you boot the image. We’ll also add this user to the group wheel so you can su to root. By default, the password for root is blank.
root@virtualbox:/home/alan # echo raspberry | pw -V /mnt/rpi/etc/ useradd -h 0 0n pi -C "Raspberry Pi User" -s /bin/csh -m
pw: user name or id required
root@virtualbox:/home/alan # echo raspberry | pw -V /mnt/rpi/etc/ useradd -h 0 -n pi -C "Raspberry Pi User" -s /bin/csh -m
root@virtualbox:/home/alan # pw -V /mnt/rpi/etc/ groupmod wheel -m pi
Next, we’ll get the UID and GID of the user pi:
root@virtualbox:/home/alan # pw -V /mnt/rpi/etc usershow pi | cut -f 3 -d :
1001
root@virtualbox:/home/alan # pw -V /mnt/rpi/etc usershow pi | cut -f 4 -d :
1001
And finally, we’ll create the home directory:
root@virtualbox:/home/alan # mkdir -p /mnt/rpi/home/pi
root@virtualbox:/home/alan # chown 1001:1001 /mnt/rpi/home/pi
root@virtualbox:/home/alan #
4. Modify start up services
In FreeBSD, you can control what services are launched during bootup by modifying /etc/rc.conf. We’ll want to make some basic additions to ensure we can access the pi after it boots. In our case, we’ll be settings the hostname, configuring the network interface, enabling DHCP and SSH, and devd. devd(8) is not strictly necessary, but it allows for userland programs to run when certain kernel events happen, such as plugging in a usb keyboard or mouse. We’ll also be disabling some other services like sendmail etc. Also, I’m adding autosize_enable=”YES” here. This allows the system to resize the UFS partition to make full use of your SD card on the first boot. This is also not strictly necessary as you can do this at a later time using gpart yourself. (See /etc/rc.d/autosize for the commands to use).
Copy the following to /mnt/rpi/etc/rc.conf:
hostname="raspberry-pi"
ifconfig_ue0="DHCP"
sshd_enable="YES"
cron_enable="NO"
devd_enable="YES"
syslogd_enable="YES"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
autosize_enable="YES"
5. Unmount the partition
At this point we’re done. There are some additional tweaks you can make such as enabling soft updates and modifying the number of available ttys but this is not necessary in order to get the image booted. If people like, I can include the options for these. For now, lets unmount the image.
root@virtualbox:/home/alan # umount /mnt/rpi
root@virtualbox:/home/alan # mdconfig -d -u md3
6. Write the image to your SD card
For this, I merely transferred the image to my Macbook and used DD to write it to my SD card. When you firstly insert the disk into the SD card reader, OSX will automatically attempt to mount any partitions it recognises. In our case, it mounts the FAT32 partition. To ensure a write is successful, you’ll need to unmount this. You can either do this in Terminal.app or use DiskUtility to unmount the drive without ejecting it. To write the image to the SD card, perform the following:
osx# dd if=/Users/alan/rpi.img of=/dev/disk4 bs=1m
This will take a few minutes to successfully write. Once complete, eject the SD card and insert it into your RPi and boot. Ensue you have HDMI connected to see any error messages which may be displayed during the boot up process.
Some Words
- I initially had some problems when I first booted whereby i received errors attempting to mount the boot drive – error 19. I cycled the power a couple of times, and booting was successful.
- Once it booted, I got the debug message alerting me that the disk had been resized and I needed to commit the changes using gpart. Unfortunately, when i plugged in my keyboard, it was unable to detect it correctly and after several tries, ignored it. I’m unsure if this is something to do with my USB keyboard or perhaps support for the usbhub wasn’t great. I haven’t investigated further hence the option to SSH.
- On third reboot, everything worked as normal. I could see the Ethernet link go to UP state and I was prompted to login. At this point, I navigated on my Macbook to my routers web UI and obtained the IP for the DHCP lease. I quickly made a static entry based on the MAC to ensure it always received the same IP using DHCP. At this point, I was able to login over SSH using the username ‘pi’ and password ‘raspberry’
- After login was successful, I quickly created a new user account and added it to the group wheel. I also locked out the pi account using ‘pw lock pi’.
- At this point, you’ll need a package manager to install applications. There are two options here. (1) Use the ports collection – this allows you to build applications from source. (2) you can use pkgng in order to install pre-built binary images. Unfortunately for us, there is no official ARM packages built for FreeBSD. There are some unofficial ones out there but most of the ones I came across are not maintained and have pretty old packages. Instead, I opted to go down the ports route (which is slow as you’ll have to compile everything) but acceptable for a playbox. You can perform (as root) ‘portsnap fetch && portsnap extract’ in order to download and extract the latest ports collection. This will take HOURS. I ran out of patience and instead downloaded the ports package directly to the RPi and extracted it. You can also shutdown, remove the SD card and merely extract the entire ports collection directly onto the SD card using another machine. This is probably the fastest option as it took me a couple of hours to extract the ports collection correctly.
- To keep ports updated, I went the subversion route instead of using portsnap. In this case, you can merely run ‘svn checkout https://
svn0.us-east.FreeBSD.org/ports/head /usr/ports’. I added this line to a cronjob to run once a week around 3am. Obviously, selecting a mirror close to you is best. Details for this are covered in the FreeBSD Handbook.
Downloads
I’ve uploaded the image I made in this post for download to save you the hassle from above if you’re looking for just a standard stock image to boot from. You can grab it from my Redbrick Account.