Skip to content
Matt Magoffin edited this page Oct 24, 2018 · 6 revisions

SolarNode Custom OS Image Guide

This guide describes the typical steps necessary for customizing one of the standard SolarNode OS images. Customizing the OS image is useful when you'd like to provide default settings and plugins, for example.

The standard SolarNode images are available at http://sourceforge.net/projects/solarnetwork/files/solarnode.

Note that the SolarNode Image Maker (NIM) tool can help you automate this process. You just need to package your configuration and other changes into tar archives and write a guestfish script to apply them to one of the standard SolarNode images.

Boot standard OS image

Download a standard OS image as your starting point, and then boot up your SolarNode hardware using that base image. In order to customize the node's settings, you'll need to create an invitation for a new SolarNode in your SolarNetwork account, and then associate the SolarNode to your SolarNetwork account using the SolarNode setup (e.g. http://solarnode/).

Customize plugins

Once associated, use the Plugins tab to install any of the additional plugins you need, and also update any outdated plugins if necessary. Configure the plugins as needed, by using the Settings tab. Once all the plugins are configured, export the settings as a CSV file using the Settings backup & restore section under Settings.

Create Auto Settings

Rename the the settings CSV file exported previously to auto-settings.csv and open it for editing. Remove all setting lines except those that apply to the plugins you configured earlier. You can tell which settings should be kept by either the timestamp of the setting or the values (you should recognize the setting values you configured moments ago).

FACTORY settings

Many SolarNode plugins allow you to configure as many components as you like. If you want the customized image to start off with the components you've configured, then you also need to keep the associated FACTORY settings you'll find in the settings CSV file. For example, imagine you configured a Modbus Serial Port component, and changed the port to /dev/ttyUSB1. In the auto-settings.csv file you'd want to keep two lines:

net.solarnetwork.node.io.modbus.FACTORY,1,1,0,2014-03-01 21:00:31
net.solarnetwork.node.io.modbus.1,serialParams.portName,/dev/ttyUSB1,0,2014-03-01 21:01:31

The first line tells SolarNetwork to instantiate one Modbus Serial Port component, and the second line sets the serial port on that component to /dev/ttyUSB1.

Copy auto settings to node

Once you've got your auto-settings.csv all set, then copy it to the node and put it in the ~solar/conf directory.

Customize OS settings

You may want to customize OS settings, such as networking or additional software.

Clean up packages

If you installed packages via apt you should be sure to remove the cached packages via apt-get clean.

Shutdown node

Shutdown the node, e.g. sudo shutdown -h now. Once completely shutdown, power off the node and pop the OS SD card into your workstation. Note the mount point, for example /media/joe/SOLARNODE.

Disassociate node

Now you need to disassociate the SolarNode from your account, so it no longer has a node ID. First you may like to create a backup of the node, under Backup & Restore under Settings. This will allow you to make further tweaks to the settings later on, if need be. Make sure to download the backup archive to your workstation and keep in a safe place.

Note all paths are relative to the SD card's mount point, and may differ from here!

Shut down the node service, and then delete the home/solar/var, home/solar/work, home/solar/conf/tls/node.jks, and home/solar/.ssh/id* directories and files.

cd /media/joe/SOLARNODE
rm -rf home/solar/var home/solar/work home/solar/conf/tls/node.jks home/solar/.ssh/id*

Remove SSH keys

Now delete the generated SSH keys, so new nodes generate their own:

rm -f etc/ssh/ssh_host_*

Zero out unused data

Use the sfill program to zero out all unused filesystem space, so that the image file can compress better. This tool is available in the secure-delete Debian package, for example.

sfill -f -l -l -z /media/joe/SOLARNODE

Umount disk Image

Unmount the disk image (umount /media/joe/SOLARNODE) and then you can use dd or a similar tool to copy the SD card into a new image file. For example, a 1GB image might be copied like this:

dd if=/dev/sdb conv=sync,noerror bs=4k count=243712
    |xz -9 >solarnode-deb8.0-pi-MYCUSTOMNODE-1GB.img.xz

Updating the image file directly

An uncompressed image file can be manipulated directly, for example to just install a new framework, tweak configuration files, or to run sfill. Often this can be faster than manipulating the image directly on a SD card.

Create a loop-back device for the image file

Use losetup to create a loop-back device that we can then mount like any other disk:

losetup -P -f --show solarnode-deb8-pi-1GB.img

That will print out the allocated device, like /dev/loop0.

Mount the image file

Using the loop-back device created on the previous step, mount the partition(s). Note some images, such as the Raspberry Pi, have two partitions (boot, SOLARNODE). This example will show a Pi image, mounting the 2nd partition. You can list the available partitions like this:

$ ls /dev/loop0*
brw-rw---- 1 root disk   7, 0 Jul 25 10:09 /dev/loop0
brw-rw---- 1 root disk 259, 0 Jul 25 10:09 /dev/loop0p1
brw-rw---- 1 root disk 259, 1 Jul 25 10:09 /dev/loop0p2

The loop0p2 is the SOLARNODE partition we need. Mount it like this:

mkdir /mnt/SOLARNODE
mount /dev/loop0p2 /mnt/SOLARNODE

At this point, the root filesystem of the image file is mounted on /mnt/SOLARNODE and can be treated like any other filesystem. You'll need to mind the permissions of any files you create, as they will be created using the ID of whatever user you're using on your host computer, not the SolarNode OS.

For example, to run sfill and zero-out data, you'd run a command like this:

sfill -f -l -l -z /mnt/SOLARNODE

Finish up

When done updating the image, the filesystem(s) must be un-mounted and the loop-back device destroyed. The commands look like this:

umount /mnt/SOLARNODE
losetup -d /dev/loop0

Now the image can be compressed and distributed.

Clone this wiki locally