Skip to content

Node OS Setup Guide Raspbian

Philip Court edited this page Nov 26, 2017 · 10 revisions

SolarNode 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:

  1. No X window system.
  2. No development tools.
  3. No daemons or servers unless required by the OS or SolarNode.
  4. SSH daemon for network access.
  5. NTP daemon for time synchronization.
  6. Monit daemon for SolarNode monitoring.
  7. 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 Raspbian and copy to SD card

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.

Boot the Raspbian Pi

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.

OS setup tasks

  1. Configure the local time zone

    Run the dpkg-reconfigure tzdata command to set the time zone appropriately.

  2. Label the root partition

     e2label /dev/mmcblk0p2 SOLARNODE
    
  3. Edit /etc/fstab to:

  4. 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
    
  5. 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
    
  6. Add a solar user, add them to dialout group, to allow use of serial ports.

     useradd -m -U -G dialout solar
    
  7. Edit /etc/default/tmpfs and set RAMTMP=yes to enable /tmp as a RAM filesystem.

  8. Remove extra console ttys to free up RAM. Edit /etc/inittab and 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
    

Software setup

Now I manually removed and added the software I deemed appropriate for the node.

  1. Replace rsyslog with busybox-syslogd, to minimize writing to the SD card:

     apt-get remove --purge rsyslog
     apt-get install busybox-syslogd
    
  2. Install monit

  3. apt-get install monit

  4. Configure /etc/default/monit to enable, e.g. START=yes

  5. Configure /etc/monit/monitrc with startup delay, e.g. set daemon 120 with start delay 240; change the statefile, idfile, and eventqueue basedir paths 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

  6. Add /etc/init.d/monit-prep.sh script that makes sure /var/run/monit exists at startup, as /var/run is 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
    
  7. chmod 755 /etc/init.d/monit-prep.sh

  8. update-rc.d monit-prep.sh defaults

  9. service monit-prep.sh start

  10. Install OpenNTPD

  11. apt-get remove --purge ntp

  12. apt-get install openntpd

  13. Edit /etc/default/openntpd and add -s to the boot parameters. This will allow NTP to adjust the clock when the system starts up, even if the time difference is very large.

  14. 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 remove to remove it from system startup, then create a Monit script /etc/monit/conf.d/openntpd with 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
    
  15. Remove nano and docs

     apt-get remove --purge nano info manpages
    
  16. Install RXTX and JNA Java libraries, to support serial ports in Java:

     apt-get install librxtx-java libjna-java
    

Remove unneeded software

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.

Add udev rule file to remove MAC address associations

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

Clean Up

As a final clean up, run apt-get clean.

Install base SolarNode platform

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.

Clone this wiki locally