raymod2
Posts: 11
Joined: Mon Oct 20, 2014 12:33 am

HOWTO: FreeBSD 11 and Nginx on Raspberry Pi B+

Mon Oct 20, 2014 2:59 am

I successfully set up a web server using FreeBSD with a Raspberry Pi B+ and I thought I would share my notes. The hardware I used is as follows (purchased from Amazon for $58.07 total):

Raspberry Pi Model B+ (B Plus) With Clear Case
Kootek 5V 2A Universal Micro USB Charger Adapter Power Supply
Transcend 16GB MicroSDHC Class10 UHS-1 Memory Card with Adapter

1) download the following file from ftp://ftp.freebsd.org/pub/FreeBSD/snaps ... ISO-IMAGES:

FreeBSD-11.0-CURRENT-arm-armv6-RPI-B-20140918-r271779.img

2) download the following files from https://github.com/raspberrypi/firmware ... aster/boot:

bootcode.bin
start.elf

3) create a bootable SD card:

diskpart (run from admin cmd)
list disk
select disk x (set x to correct drive number)
clean
exit
physdiskwrite.exe -u FreeBSD-11.0-CURRENT-arm-armv6-RPI-B-20140918-r271779.img
(alternately you can use Win32 Disk Imager which is faster)
copy /y bootcode.bin x: (set x to correct drive letter)
copy /y start.elf x: (set x to correct drive letter)
(safely eject the SD card)

4) perform first time boot:

insert SD card
plug in monitor+keyboard+Ethernet
attach power (it should boot to the login prompt)
login as root (empty password)
passwd (set root password)

5) allow root to login over SSH:

vi /etc/ssh/sshd_config (edit or add the following line)
PermitRootLogin yes

6) configure static IP:

vi /etc/rc.conf (edit or add the following lines)
ifconfig_ue0="inet 192.168.1.5 netmask 255.255.255.0" (set IP as desired)
defaultrouter="192.168.1.1" (set gateway as desired)

7) make the following change if you are having intermittent boot problems (error 19):

echo 'hw.bcm2835.sdhci.hs="0"' >> /boot/loader.conf

8) reboot to apply the above changes (you can use SSH for the following steps)

9) configure date and time:

tzsetup (set local time zone)
ntpdate pool.ntp.org (set current date and time)
echo 'ntpd_enable="YES"' >> /etc/rc.conf (enable time daemon at boot)
service ntpd start (enable time daemon now)

10) increase swap space to prevent compiler crashes below:

dd if=/dev/zero of=/usr/swap0 bs=1m count=128
chmod 0600 /usr/swap0
echo 'md99 none swap sw,file=/usr/swap0 0 0' >> /etc/fstab
swapon -aq

11) download and compile nginx:

portsnap fetch extract
cd /usr/ports/www/nginx
make config-recursive
make install clean

12) enable nginx:

echo 'nginx_enable="YES"' >> /etc/rc.conf
/usr/local/etc/rc.d/nginx start


There were two issues that I ran into. The first is that it only seems to be using 256MB of RAM (dmesg | grep memory). The Raspberry Pi B+ has 512MB of RAM. This probably caused or contributed to the compiler crashes. It displayed "out of swap space" on the console (this was NOT displayed in my SSH session so I missed it at first). Setting up a swap file as described above fixed the compiler problem but it would also be good to know how to use all available RAM. If anyone knows how please let me know.

The other problem was flakiness with SD cards. With my 16GB Transcend SD card I was getting intermittent boot failures. It sometimes displayed "Mounting from ufs:/dev/mmcsd0s2a failed with error 19" and then went to a "mountroot>" prompt. The hw.bcm2835.sdhci.hs="0" setting reliably fixed this for me. Before the change I performed 10 reboot cycles and it failed 5 times. After the change I performed 20 boot cycles with no failures. I also tried using a 32GB Sandisk SD card and I couldn't get it to boot at all. It kept displaying the following errors:

mmcsd0: Error indicated: 1 Timeout
g_vfs_done():mmcsd0s2a[READ(offset=852987904, length=4096)]error = 5
vnode_pager_getpages: I/O read error
vm_fault: pager read error, pid 1 (init)

I'm not sure if this is a software problem or a hardware problem. Both SD cards were brand new and never used. I suspect there are issues with FreeBSD because I never see a failure until FreeBSD starts to boot.

raymod2
Posts: 11
Joined: Mon Oct 20, 2014 12:33 am

Re: HOWTO: FreeBSD 11 and Nginx on Raspberry Pi B+

Wed Oct 22, 2014 12:26 am

UPDATE: There are some new boot files at the following URL:

https://github.com/kientzle/crochet-fre ... rryPi/boot

Download the following files and copy them to your MSDOS partition:

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

This fixes the problem with RAM (all 512MB is now available). It does not fix the SD card problems, however.

BigJacobus
Posts: 7
Joined: Sat Sep 13, 2014 9:47 pm

Re: HOWTO: FreeBSD 11 and Nginx on Raspberry Pi B+

Thu Oct 23, 2014 12:28 am

I think your step 10 is what I have been missing. Its good to see what others have been doing to get things working.

BigJacobus
Posts: 7
Joined: Sat Sep 13, 2014 9:47 pm

Re: HOWTO: FreeBSD 11 and Nginx on Raspberry Pi B+

Thu Oct 23, 2014 7:15 pm

Nope it was going back and getting the same files that you had to get. I am finally able to build some ports.

raymod2
Posts: 11
Joined: Mon Oct 20, 2014 12:33 am

Re: HOWTO: FreeBSD 11 and Nginx on Raspberry Pi B+

Mon Oct 27, 2014 4:21 pm

I can confirm that it is no longer necessary to create a swap partition (step 10 in the original post) when using the latest boot files which recognize the full 512MB of RAM.

raymod2
Posts: 11
Joined: Mon Oct 20, 2014 12:33 am

Re: HOWTO: FreeBSD 11 and Nginx on Raspberry Pi B+

Wed Oct 29, 2014 1:59 am

I recently noticed that my instructions above for enabling the NTP daemon are insufficient. It works until the next reboot cycle and then ntpd will fail to load during boot. The problem is that RPi has no battery to keep track of time when it is powered off so when it boots there is a large error in the current time. When ntpd loads it notices this large error. It then "panics" and exits after logging the following message to syslogd (which you won't see because it isn't running):

Oct 28 12:46:38 raspberry-pi ntpd[731]: time correction of 23617 seconds exceeds sanity limit (1000); set clock manually to the correct UTC time.

The solution is to use the ntpd_sync_on_start variable which will add the -g flag when starting ntpd. This flag allows a one time exception to the sanity check for each boot. Here are the new instructions:

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

frbox
Posts: 5
Joined: Sun Jan 11, 2015 10:02 am

Re: HOWTO: FreeBSD 11 and Nginx on Raspberry Pi B+

Sun Jan 11, 2015 10:57 am

Hi,

I'm testing FreeBSD-11.0-CURRENT-arm-armv6-RPI-B-20141222-r276066.img with the lastest files from https://github.com/raspberrypi/firmware for my Raspberry PI B+:
- bootcode.bin
- fixup.dat
- fixup_cd.dat
- start.elf
- start_cd.elf

I have copied that on a 16GB Kingston SD card. NOOBS and Raspbian work.

I wire HDMI screen and micro USB 2A power.
I can (or not) wire an 2001 Apple FR USB keyboard.
I can (or not) wire an Ethernet cable of my home network.

I always boot on this screen:

Code: Select all

In: serial
Out: lcd
Err: lcd
mbox: Timeout waiting for response
bcm2835: Could not set USB power state
Net: Net Initialization Skipped
No ethernet found.
Hit any key to stop autoboot: 0
reading uEnv.txt
89 bytes read in 8948 ms (0 Bytes/s)
Importing environment from mmc ...
reading ubldr
251119 bytes read in 56608 ms (3.9 KiB/s)
libfdt fdt_check_header(): FDT_ERR_BADMAGIC
## Starting application at 0x02000054 ...
Consoles: U-Boot console
Compatible U-Boot API signature found @1eb682a8

FreeBSD/armv6 U-Boot loader, Revision 1.2
([email protected], Wed Dec 24 16:51:33 UTC 2014)

DRAM: 496MB
Number of U-Boot devices: 1
U-Boot env: loaderdev not set, will probe all devices.
Found U-Boot device: disk
  Probing all disk devices...
  Checking unit=0 slice=<auto> partition=<auto>... good.
Loading /boot/defaults/loader.conf
/boot/kernel/kernel data=0x4f54a4+0xb6b5c syms=[0x4+0x8cbd0+0x4+0x53f47]

Hit [Enter] to boot immediately, or any other key for command prompt.
Booting [/boot/kernel/kernel]...

Type '?' for a list of commands, 'help' for more detailed help.
loader>
During the startup and after this last line I can't use the keyboard. Even I press any key, nohting happens.

Do you have any idea?

Thx

raymod2
Posts: 11
Joined: Mon Oct 20, 2014 12:33 am

Re: HOWTO: FreeBSD 11 and Nginx on Raspberry Pi B+

Mon Jan 12, 2015 10:41 pm

It was mentioned in another thread that there was a regression on 11.0-CURRENT that broke Raspberry Pi. It was subsequently fixed and I see that a new build was uploaded today. I'd give that one a try:

FreeBSD-11.0-CURRENT-arm-armv6-RPI-B-20150111-r276981.img.bz2

frbox
Posts: 5
Joined: Sun Jan 11, 2015 10:02 am

Re: HOWTO: FreeBSD 11 and Nginx on Raspberry Pi B+

Tue Jan 13, 2015 6:45 am

Thanks!
It works on RPi B+
I don't need replace some files. I copy only the .img

hackware
Posts: 2
Joined: Thu Nov 19, 2015 4:13 am

Re: HOWTO: FreeBSD 11 and Nginx on Raspberry Pi B+

Thu Nov 19, 2015 4:19 am

wow...

glad I found this thread...

just bought a pi v2 (1gb ram! :-), but was dreading learning linux all over again...

one of the first things I'm gonna attack is getting freebsd working with a real time clock module...

thanx bunches for your work so far... :-)

william...

Return to “FreeBSD”