BLog

ImprintImpressum
PrivacyDatenschutz
DisclaimerHaftung
Downloads 

FreeBSD on a BeagleBone Black with a swap partition

The Beaglebone Black comes with 512 MByte of RAM which might be not enough when it comes to building huge software distributions from sources. On Unix like systems, memory constraints can be overcome by assigning a swap partition to the OS, which usually resides on a fast internal random access mass storage device. The BeagleBone Black utilizes flash memory for mass storage, and the used flash memory is neither fast nor designed for unlimited random access - flash memory suffers quite a bit from frequent writes. So, in order to preserve the service life of the flash memory, we want to put the swap partition on a network storage facility.

In my network, I got a FreeBSD file server, and on this I exported a NFS share for holding the swap partition for the BBB.

File /etc/rc.conf:

rpcbind_flags="-h 192.168.1.1"
rpc_lockd_flags="-h 192.168.1.1 -p 997"
rpc_statd_flags="-h 192.168.1.1 -p 998"
mountd_flags="-r -h 192.168.1.1 -p 999"
nfs_server_flags="-t -h 192.168.1.1"
rpcbind_enable="YES"
rpc_lockd_enable="YES"
rpc_statd_enable="YES"
mountd_enable="YES"
nfs_client_enable="YES"
nfs_server_enable="YES"
nfsv4_server_enable="YES"
nfsuserd_enable="YES"

File /etc/exports:

#path   options			clients
/bbb	-mapall=root -alldirs	-network 192.168.1.0 -mask 255.255.255.0
V4: /bbb

Then I created the swap storage for the BeagleBone Black using the following command:
dd if=/dev/zero of=/bbb/.swap bs=1m count=960

On the BeagleBone Black I added to the file /etc/rc.conf the following entries:

nfs_client_enable="YES"
nfsuserd_enable="YES"

And finally, to file /etc/fstab, I added:

192.168.1.1:/bbb	/mnt	nfs	rw,failok,retrycnt=1,noatime,readahead=4,intr,nfsv4	0	0
md99			none	swap	sw,file=/mnt/.swap,late					0	0

On restart the BeagleBone Black comes up with 960 MByte swap memory, and building huge software packages - here LLVM 5.0.0 - is going to finish successfully, although, it takes its time - top:

CPU: 96.1% user,  0.0% nice,  3.5% system,  0.4% interrupt,  0.0% idle
Mem: 67M Active, 10M Inact, 112K Laundry, 106M Wired, 57M Buf, 309M Free
Swap: 960M Total, 23M Used, 937M Free, 2% Inuse

  PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME    WCPU COMMAND
 5832 root          1  75    0 78976K 46700K RUN      0:09  87.10% c++
 5830 root          1  75    0 92220K 61792K RUN      0:19  55.11% c++
 5833 root          1  40    0  7628K  3264K RUN      0:00   1.49% top
 5128 root          1  40    0 11836K  4856K select   0:00   0.04% sshd
  507 root          1  40    0  9204K  9088K select   0:18   0.03% ntpd
  610 root          1  62    0 28192K  9008K select   0:36   0.00% ninja
  607 root          1  40    0  9080K  4308K select   0:07   0.00% tmux
  556 root          1   8    0  6232K   720K nanslp   0:02   0.00% cron
  466 root          1   4    0  6416K  1732K select   0:01   0.00% nfsuserd
  464 root          1  40    0  6416K  1732K select   0:01   0.00% nfsuserd
  467 root          1   4    0  6416K  1732K select   0:01   0.00% nfsuserd
  350 root          1  40    0  6168K  1700K select   0:01   0.00% syslogd
  465 root          1   4    0  6416K     8K sbwait   0:01   0.00% nfsuserd
 5130 root          1  16    0  7272K  3692K pause    0:00   0.00% csh
  608 root          1  16    0  7232K     0K pause    0:00   0.00% <csh>
 5829 root          1   8    0 65056K 33304K wait     0:00   0.00% c++
 5831 root          1   8    0 65056K 33304K wait     0:00   0.00% c++
  552 root          1  40    0 11756K  3400K select   0:00   0.00% sshd
  599 root          1  60    0  6152K  1532K ttyin    0:00   0.00% getty
  462 root          1  16    0  6416K     0K pause    0:00   0.00% <nfsuserd>

A problem may arise, in case the remote file system is not available, and the startup script which would mount the nfs share simply hangs forever, and unfortunately, this happens when sshd isn't loaded yet. So, there is no chance to fix the issues remotely, other than by the way of a serial console. The workaround is, to get sshd started early in the boot sequence. For this to happen, we need to edit /etc/rc.d/sshd. In there, replace the line starting with # REQUIRE: ... by the following in purple.

#!/bin/sh
#
# $FreeBSD: head/sbin/init/rc.d/sshd 333520 2018-05-12 08:23:17Z des $
#

# PROVIDE: sshd
# REQUIRE: NETWORKING
# BEFORE: mountcritremote
# KEYWORD: shutdown

. /etc/rc.subr

...

Keywords: BeagleBone, FreeBSD, Swap-partition

Copyright © Dr. Rolf Jansen - 2018-07-10 18:16:20

PROMOTION