-
Notifications
You must be signed in to change notification settings - Fork 2
Node OS Setup Guide Raspbian
This guide describes the steps I took to create a "minimal" Raspbian based system on a Raspberry Pi computer, similar to the SolarNode OS Setup Guide for Debian 7. The overall goals were these:
- No X window system.
- No development tools.
- No daemons or servers unless required by the OS or SolarNode.
- SSH daemon for network access.
- NTP daemon for time synchronization.
- Monit daemon for SolarNode monitoring.
- Java 7 JRE.
With these goals in mind, let's dive in. Raspbian comes pre-configured as an OS disk image already, so our tasks mainly consist of removing packages not meeting our requirements and tweaking some settings a bit.
Note: Binary images for the SolarNode Raspbian OS are also available here: http://sourceforge.net/projects/solarnetwork/files/solarnode/pi These are great if you are after a quick OS setup (but they do not always contain the latest updates), if you want the latest and greatest you should continue reading below.
Download the Raspbian image from http://www.raspberrypi.org/downloads. That page also has links and instructions for copying the image onto a SD card, for example http://elinux.org/RPi_Easy_SD_Card_Setup.
Insert your freshly minted SD card into the Pi, and power the device on. You'll land on an initial setup screen. I tweaked the GPU memory to 16MB (the minimum) since a SolarNode doesn't use the graphics hardware.
-
Configure the local time zone
Run the
dpkg-reconfigure tzdatacommand to set the time zone appropriately. -
Label the root partition
e2label /dev/mmcblk0p2 SOLARNODE -
Edit
/etc/fstabto: -
Change the options for root filesystem to noatime,nodiratime,errors=remount-ro, it should look like this:
LABEL=SOLARNODE / ext4 noatime,nodiratime,errors=remount-ro 0 1 -
Add a manual entry for
/run/shm. Debian provides this by default, but adds the noexec flag, which causes bundles with native libraries in them to fail to load. Add an entry like this:tmpfs /run/shm tmpfs rw,nosuid,nodev,exec,relatime,size=102860k 0 0 -
Add a solar user, add them to dialout group, to allow use of serial ports.
useradd -m -U -G dialout solar -
Edit
/etc/default/tmpfsand set RAMTMP=yes to enable /tmp as a RAM filesystem. -
Remove extra console ttys to free up RAM. Edit
/etc/inittaband comment out the TTYs you don't need, e.g.1:2345:respawn:/sbin/getty 38400 tty1 2:23:respawn:/sbin/getty 38400 tty2 #3:23:respawn:/sbin/getty 38400 tty3 #4:23:respawn:/sbin/getty 38400 tty4 #5:23:respawn:/sbin/getty 38400 tty5 #6:23:respawn:/sbin/getty 38400 tty6
Now I manually removed and added the software I deemed appropriate for the node.
-
Replace rsyslog with busybox-syslogd, to minimize writing to the SD card:
apt-get remove --purge rsyslog apt-get install busybox-syslogd -
Install monit
-
apt-get install monit -
Configure
/etc/default/monitto enable, e.g. START=yes -
Configure
/etc/monit/monitrcwith startup delay, e.g. set daemon 120 with start delay 240; change thestatefile,idfile, andeventqueue basedirpaths to start with /var/run instead of /var/lib, e.g.set idfile /var/run/monit/id set statefile /var/run/monit/state set eventqueue basedir /var/run/monit/events
-
Add
/etc/init.d/monit-prep.shscript that makes sure /var/run/monit exists at startup, as/var/runis a tmpfs filesystem.#!/bin/sh ### BEGIN INIT INFO # Provides: monit-prep # Required-Start: $remote_fs # Required-Stop: $remote_fs # X-Start-Before: monit # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: prepare for monit ### END INIT INFO DIR=/var/run/monit EDIR=$DIR/events NAME=monit-prep if [ ! -d $DIR ]; then mkdir -p $DIR chmod 755 $DIR fi if [ ! -d $EDIR ]; then mkdir -p $EDIR chmod 700 $EDIR fi exit 0 -
chmod 755 /etc/init.d/monit-prep.sh -
update-rc.d monit-prep.sh defaults -
service monit-prep.sh start -
Install OpenNTPD
-
apt-get remove --purge ntp -
apt-get install openntpd -
Edit
/etc/default/openntpdand add-sto the boot parameters. This will allow NTP to adjust the clock when the system starts up, even if the time difference is very large. -
With the -s flag, if NTP can't connect to the network it can prevent the node from booting for a long time. Instead of letting the OS start OpenNTP, we can let Monit do this later on. Run
update-rc.d openntpd removeto remove it from system startup, then create a Monit script/etc/monit/conf.d/openntpdwith the following:check host localhost with address 127.0.0.1 start program = "/etc/init.d/openntpd start" stop program = "/etc/init.d/openntpd stop" if failed host 127.0.0.1 port 123 type udp protocol ntp3 then restart -
Remove nano and docs
apt-get remove --purge nano info manpages -
Install RXTX and JNA Java libraries, to support serial ports in Java:
apt-get install librxtx-java libjna-java
Raspbian comes loaded with development tools (gcc, g++, python, etc) and X11 stuff (x11, lxde, etc) that are of no use to a SolarNode. They can all be removed. I used aptitude to browse the installed packages, and removed these things.
Further savings can be found by installing the deborphan and debfoster packages. Use those to identify non-essential packages and remove them.
The Debian installer will have set up a udev rule that associates the ethernet and devices with persistent device names, eth0 and wlan0, based on those devices' hardware MAC addresses. In order to make this system easier to clone onto other SD cards, I added a custom udev rules file /etc/udev/rules.d/a10-solarnode.rules with the following content:
# Rename network interfaces NOT using MAC addresses, so this image can be copied to other devices
SUBSYSTEM=="net", DRIVERS=="?*", KERNEL=="eth*", NAME="lan%n"
SUBSYSTEM=="net", DRIVERS=="?*", KERNEL=="wlan*", NAME="wlan%n"
This will map ethernet devices to lanX and WiFi to wlanX where X starts at 0. This thus provides the lan0 and wlan0 network device names.
Finally, edit /etc/network/interfaces to rename all references to eth0 to lan0. There should be only two, e.g.
# The primary network interface
iface lan0 inet dhcp
As a final clean up, run apt-get clean.
Now we'll deploy a basic SolarNode platform, and configure it to startup when the node boots. See Deploying the SolarNode application for more information.