Skip to content

Node OS Setup Guide Raspbian

Matt Magoffin edited this page Oct 22, 2019 · 10 revisions

SolarNode OS Setup Guide - Raspbian

⚠️ WARNING: this is a very old guide, meant for advanced developers. If you are looking to get started with a SolarNode device, there are pre-built OS images for many popular devices.

This guide describes the steps I took to create a "minimal" Raspbian based system on a Raspberry Pi computer. The steps are very similar to what is described in the SolarNode OS Setup Guide for Debian 9. This guide just documents the Raspberry Pi specific differences from that guide.

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

    Note to delete the pi user you must log in to the console as root, but to do that you might need to first reset the root password to a known value. Once the solar user is set up, then disable the root password with sudo passwd -dl root.

     userdel pi
     useradd -m -U -G dialout,sudo -s /bin/bash solar
     passwd solar # set password to 'solar'
    
  5. Edit /etc/default/tmpfs and set RAMTMP=yes to enable /tmp as a RAM filesystem.

     # mount /run/lock as a tmpfs (separately from /run).  Defaults to yes;
     # set to no to disable (/run/lock will then be part of the /run tmpfs,
     # if available).
     #RAMLOCK=yes
    
     # mount /run/shm as a tmpfs (separately from /run).  Defaults to yes;
     # set to no to disable (/run/shm will then be part of the /run tmpfs,
     # if available).
     #RAMSHM=yes
    
     # mount /tmp as a tmpfs.  Defaults to no; set to yes to enable (/tmp
     # will be part of the root filesystem if disabled).  /tmp may also be
     # configured to be a separate mount in /etc/fstab.
     RAMTMP=yes
    
     # Size limits.  Please see tmpfs(5) for details on how to configure
     # tmpfs size limits.
     #TMPFS_SIZE=20%VM
     #RUN_SIZE=10%
     #LOCK_SIZE=5242880 # 5MiB
     SHM_SIZE=50%
     #TMP_SIZE=
    
     # Mount tmpfs on /tmp if there is less than the limit size (in kiB) on
     # the root filesystem (overriding RAMTMP).
     #TMP_OVERFLOW_LIMIT=1024
    

Raspberry Pi udev rules

These have been adapted from the raspberrypi-sys-mods package, stored in /etc/udev/rules.d/a10-solarnode-pi.rules as:

SUBSYSTEM=="input", GROUP="input", MODE="0660"
SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660"
SUBSYSTEM=="spidev", GROUP="spi", MODE="0660"
SUBSYSTEM=="bcm2835-gpiomem", GROUP="gpio", MODE="0660"

SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\
	chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\
	chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio;\
	chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\
'"

KERNEL=="ttyAMA[01]", PROGRAM="/bin/sh -c '\
	ALIASES=/proc/device-tree/aliases; \
	if cmp -s $ALIASES/uart0 $ALIASES/serial0; then \
		echo 0;\
	elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then \
		echo 1; \
	else \
		exit 1; \
	fi\
'", SYMLINK+="serial%c"

KERNEL=="ttyS0", PROGRAM="/bin/sh -c '\
	ALIASES=/proc/device-tree/aliases; \
	if cmp -s $ALIASES/uart1 $ALIASES/serial0; then \
		echo 0; \
	elif cmp -s $ALIASES/uart1 $ALIASES/serial1; then \
		echo 1; \
	else \
		exit 1; \
	fi \
'", SYMLINK+="serial%c"

And /lib/udev/rules.d/15-i2c-solarnode-pi.rules as:

SUBSYSTEM=="i2c|spi", ENV{MODALIAS}=="?*", ENV{OF_NAME}=="?*", ENV{OF_COMPATIBLE_0}=="?*", RUN+="/usr/share/solarnode/i2cprobe.sh"

with a newly created /usr/share/solarnode/i2cprobe.sh (mode 0775) script:

#!/bin/sh
modprobe ${MODALIAS} || modprobe "of:N${OF_NAME}T<NULL>C${OF_COMPATIBLE_0}"

Modprobe rules

These have been adapted from the raspberrypi-sys-mods package, stored in /etc/modprobe.d/blacklist-solarnode-pi.conf as:

blacklist rtl8192cu
blacklist rtl8xxxu

Sysctl rules

These have been adapted from the raspberrypi-sys-mods package, stored in /etc/sysctl.d/solarnode-pi.conf as:

kernel.printk = 3 4 1 3
vm.min_free_kbytes = 16384

WiFi configuration

Adapted from the raspberrypi-sys-mods package, added a /lib/systemd/system/solarnode-wpa-config.service that copies a /boot/wpa_supplicant.conf file to /etc/wpa_supplicant/wpa_supplicant-wlan0.conf if found. The service is:

[Unit]
Description=Copy user wpa_supplicant.conf
ConditionPathExists=/boot/wpa_supplicant.conf
[email protected]
[email protected]

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/mv /boot/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
ExecStartPost=/bin/chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf

[Install]
WantedBy=multi-user.target

Hardware watchdog

The Raspberry Pi has a hardware "watchdog" timer that can be used to automatically restart after a fault. First update /boot/config.txt to add the following:

	dtparam=watchdog=on

Next, create /etc/modprobe.d/bcm2835-wdt.conf With the following:

	options bcm2835_wdt heartbeat=14 nowayout=0

Finally, edit /etc/systemd/system.conf and change these lines (note CrashReboot is not related to the watchdog timer, but allows systemd to reboot the device if the system has a software crash):

	CrashReboot=yes
	RuntimeWatchdogSec=14

Software setup

Now I manually removed and added the software I deemed appropriate for the node, as described in the SolarNode OS Setup Guide for Debian 8 Software setup section.

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. Further savings can be found by installing the deborphan and debfoster packages. Use those to identify non-essential packages and remove them.

Clone this wiki locally