Skip to content

Node OS Setup Guide Debian 6

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

Node OS Setup Guide Debian 6

⚠️ 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" Debian 6 based system with base SolarNode deployment configured on an eBox 3300 (NorhTec JrMX) computer. The overall goals were these:

  1. No X window system.
  2. No development tools.
  3. No daemons or servers unless required by Debian or SolarNode.
  4. SSH daemon for network access.
  5. NTP daemon for time synchronization.
  6. Monit daemon for SolarNode monitoring.
  7. Boot from SD card.

With these goals in mind, let's dive in. You'll need a Linux-based system to work with, I used a Fedora system but any modern distribution should do.

Download Debian 6 and copy to USB stick

Download the Debian 6 (squeeze) installer CD. This should be the full 650MB CD, not the netboot image, so it can install the base system without needing the network. You can get the image from

http://www.debian.org/CD/http-ftp/#stable

Once you have the .iso image downloaded, use unetbootin to copy the image to a USB stick. This is a GUI tool that will copy the installer image to the USB stick and make sure it can boot (in theory dd can be used as well, if you're comfortable with that program already). Modern Linux distributions provide unetbootin, e.g. apt-get install unetbootin on Debian-based systems or yum install unetbootin on Fedora-based ones.

Insert your USB stick into your system, run unetbootin as root, and select the Debian .iso image file you downloaded. After a little while, it will complete and offer to reboot your system, which you can decline and then remove the USB stick.

Boot into the Debian installer

Insert the Debian installer USB stick into the USB port on the back of the eBox and a 512MB or larger SD card into the SD slot. You'll need a monitor and keyboard (USB or PS/2) plugged in as well, but no mouse is required. Turn the node on, and quickly press the Delete key to enter the BIOS setup utility.

Make sure the BIOS boots from the USB stick first, under the Boot menu. The BIOS should list both the USB and SD disks, as USB: and HDD: options, respectively.

Next go to the Advanced > IDE Configuration screen and make sure the Standard IDE Compatible setting is set to Enabled.

Now you can exit the BIOS configuration - F10 to save and exit - and the unetbootin boot menu should appear. Choose the Expert install mode, and let the Debian installer load.

Debian install options

Here are some important options I chose during the Debian install:

  1. DHCP for network configuration, with solarnode.localdomain as the host name.
  2. No root user, with a single solar user.
  3. No NTP time synchronization. The installer will install ntpd but we want to install openntpd manually later, which is smaller and easier to manage.
  4. Partition the SD card with a single ext2 filesystem, with a label SOLARNODE and the noatime option enabled. Also mark this partition bootable. If your card is larger than 512MB, you can create a partition sized smaller than the full SD card, so the partition can be cloned more easily. I created a 700MB partition (the SD card was 8GB).
  5. No swap partition. This is to minimize wear on the SD card.
  6. Select the most recent available i386 kernel.
  7. Configure a local apt mirror, without the non-free and without the contrib repositories used (they are not needed).
  8. No to adding/selecting software now. We'll do this manually later.
  9. Install the Grub boot loader.

At this point, the installer should complete. You can reboot the node, but un-plug the USB stick before the BIOS RAM check completes, so the node boots from the newly minted SD card.

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 localepurge to remove excess locale data:#!sh

     apt-get install localepurge
    
  3. Install sshd

     apt-get install ssh
    
  4. Install OpenNTPD

  5. Edit /etc/apt/sources.list to add the backports source, e.g. deb http://backports.debian.org/debian-backports squeeze-backports main. Wheezy note: OpenNTPD is available in the main repository, so no need to add the backports source.

  6. I also commented out all '-src' sources, and the cdrom source (which is really the USB stick). From then on, the system will install by downloading over the network.

  7. apt-get install openntpd

  8. 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.

  9. Remove nano and docs

     apt-get remove --purge nano info manpages
    
  10. Install Java (this pulls in a whopping 100MB+ of stuff)apt-get install openjdk-6-jre-headless

  11. Install monit

  12. apt-get install monit

  13. Configure /etc/default/monit to enable, e.g. startup=1

  14. Configure /etc/monit/monitrc e.g. set daemon 120 with start delay 240

  15. Install rsync (required for node database backups)

     apt-get install rsync
    

Further savings can be found by installing the deborphan and debfoster' packages. Use those to identify non-essential packages and remove them.

WiFi configuration

If you plan to use WiFi, you'll need to install some firmware for the radio and install the wpasupplicant package.

  1. apt-get install wpasupplicant
  2. Copy the rtl8192sfw.bin file to /lib/firmware/RTL8192SU/rtl8192sfw.bin. You can Google for this file, e.g. https://bugs.launchpad.net/ubuntu/+source/linux/+bug/492034/comments/35. Note you probably need to create the RTL8192SU directory in that path.

Wheezy note: Use the /lib/firmware/rtlwifi/rtl8712u.bin firmware, available at https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/tree/rtlwifi/rtl8712u.bin?id=HEAD

  1. Configure a wlan0 device in /etc/network/interfaces to match your network settings, e.g.

     # WiFi
     auto wlan0
     iface wlan0 inet dhcp
       wpa-ssid mywifi
       # hexadecimal psk, use wpa\_passphrase to generate
       wpa-psk c0c5618c9d2efc45d02db5b460...
    

Use filesystem labels instead of device UUIDs in boot configuration

The Debian installer will have configured both fstab and Grub to use device UUIDs to specify which device to use for the root filesystem. In order to make this system easier to clone onto other SD cards, I tweaked some of the settings so that the SOLARNODE filesystem label I set up during installation is referenced instead.

  1. Update /etc/fstab to use labels instead of UUID:

  2. For the root filesystem, change UUID=XXX to LABEL=SOLARNODE, e.g.

       LABEL=SOLARNODE / ext2 noatime,errors=remount-ro 0 1
    
  3. Remove the /media/cdrom0 entry (this is just a little bit of tidying).

  4. Update Grub to use labels instead of UUIDs. See http://ubuntuforums.org/showpost.php?p=9585951&postcount=13 for reference.

  5. Change /etc/default/grub so that GRUB_DISABLE_LINUX_UUID="true"

  6. Change /etc/grub.d/10_linux to insert this line

       linux_root_device_thisversion="LABEL=`e2label ${GRUB_DEVICE_BOOT} 2>/dev/null`"
    

    directly before these lines (around line 81):

         cat << EOF
       	echo	'$message'
       	linux	${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
       EOF
    
  7. Change /usr/lib/grub/grub_mkconfig_lib to replace these lines (around line 127):

     # If there's a filesystem UUID that GRUB is capable of identifying, use it;
     # otherwise set root as per value in device.map.
     echo "set root='`${grub_probe} --device ${device} --target=drive`'"
     if fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then
       echo "search --no-floppy --fs-uuid --set ${fs_uuid}"
     fi
    

    to these lines:

     # If there's a filesystem UUID that GRUB is capable of identifying, use it;
     # otherwise set root as per value in device.map.
     echo "set root='`${grub_probe} --device ${device} --target=drive`'"
     if auto_label="`e2label ${device} 2>/dev/null`"; then
       echo "search --no-floppy --label ${auto_label} --set root"
     elif fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then
       echo "search --no-floppy --fs-uuid --set ${fs_uuid}"
     fi
    
  8. Change /boot/grub/device.map to the following:

     (hd0)	/dev/disk/by-label/SOLARNODE
    
  9. Run update-grub to regenerate /boot/grub/grub.cfg. Verify you ended up with a menu entry in /boot/grub/grub.cfg with lines similar to the following (note the --label SOLARNODE and LABEL=SOLARNODE parts):

     search --no-floppy --label SOLARNODE --set root
     echo	'Loading Linux 2.6.32-5-486 ...'
     linux	/boot/vmlinuz-2.6.32-5-486 root=LABEL=SOLARNODE ro  quiet
    

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
allow-hotplug lan0
iface lan0 inet dhcp

Remove extra console ttys

Free up RAM by disabling some extra console TTYs. 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

Install ifplugd to manage network interfaces

Sometimes the networking on a node can be unreliable. Using ifplugd can help ensure the interface is running.

  1. apt-get install ifplugd
  2. Edit /etc/default/ifplugd, and update the INTERFACES setting, e.g. INTERFACES="lan0 wlan0"
  3. Check /etc/network/interfaces to ensure the ones managed by ifplugd don't have auto set, e.g. comment out (or remove) lines like #auto wlan0.

Install base SolarNode platform

Now we'll deploy a basic SolarNode platform, and configure it to startup when the node boots. A minimal SolarNode platform based on Apache Felix is available in Subversion as a tar archive named base-node.tgz at http://solarnetwork.svn.sourceforge.net/viewvc/solarnetwork/osgi/solarnode-deploy/trunk/felix/.

  1. Copy base-node.tgz SolarNode archive to node (use scp) and untar as the solar user from within the ~solar directory.
  2. Copy init script conf/sample/solarnode-felix-ramdisk.sh (extracted from base-node.tgz) to /etc/init.d/solarnode.
  3. Copy monit script conf/sample/solarnode.monit extracted from base-node.tgz) to /etc/monit/conf.d/solarnode.
Clone this wiki locally