Gumstix Boot Scripts

This post covers the basics of setting up a script to run at boot on a Gumstix device (with Buildroot or OE). As the Gumstix devices use Linux as their OS of choice, this method will apply to any Linux machine running similar versions of things, though your particular distribution may have a preferred method (for instance Ubuntu now uses upstart). I’m considering this article to be Gumstix specific as most System V based distributions will have a series of scripts enabling you to manage startup scripts more easily. This article is still applicable if you want to perform the task manually though.

The way that things work with the System V init daemon (and compatible systems) is generally:

  • At boot, the daemon iterates over a series of symlinks in /etc/rcx.d/, where x is the runlevel that is being entered at the time.
  • These symlinks point to scripts within /etc/init.d/ which perform the actual tasks required.

Assume you have a program at /home/root/myApp that you wish to run automatically on boot. The first thing to do is add a script into /etc/init.d/ which does exactly that. We will call it myApp.sh to indicate which program it is going to run, but the name isn’t significant as long as it’s meaningful to you. You should change to the correct directory:

cd /etc/init.d/

You can then use your favourite editor to create the script with the following content:

#!/bin/sh
/home/root/myApp &

The & is important here if your program is expected to continue running for a while (or forever) as it runs the program as a background task (meaning that the startup process will continue as soon as your script has begun executing). If you forget the & then the boot process will wait for your program to exit and you won’t be able to (for instance) log in using SSH until this happens, if it ever does. This script should be marked as executable:

chmod +x myApp.sh

Your next step is to add a symlink to this script from /etc/rc5.d/. This is where the boot process actually picks up the script from. There are other places you can link from if your program does something deep down in the system and needs to run really early in the boot process, but in general for user apps you want rc5.d. The symlinks in this directory all follow a standard naming scheme:

Syyxxxxxxx

Where yy is a number which provides the ordering for when the scripts are run and xxxxxxx is a name given by you for your own reference (i.e. the system doesn’t care about it). For those of you of an inquisitive nature, the “S” (uppercase) means to run this script when the system is starting up, as opposed to shutting down.

The highest number script which is generally pre-installed on a basic Gumstix Buildroot or OE system is S90 so I usually pick numbering starting at S95. Change to the /etc/rc5.d/ directory and then create the symlink:

cd /etc/rc5.d/
ln -s ../init.d/myApp.sh S96myApp

The reason for choosing S96 here is that in general I have another script at S95 which sets up some extra things such as ethernet bridging. You can check the symlink was created correctly by running ls -la in the /etc/rc5.d/ directory. You should see a line similar to the following among the output of this command:

lrwxrwxrwx 1 root root 18 2009-08-21 15:28 S96myApp -> ../init.d/myApp.sh

The next time the Gumstix device boots the script should run and start your program in the background. If you want to test it beforehand, simply run

/etc/rc5.d/S96myApp

Though remember that your target script will be started as a background task, so you can’t exit via Ctrl+C.

Facebooktwittergoogle_plusredditpinterestFacebooktwittergoogle_plusredditpinterest
Loading Facebook Comments ...
  1. […] your PC. As BlueZ 4.x enforces the use of PINs much more than 3.x did, you’ll need to add a boot script to your Gumstix (a symlink in /etc/rc5.d/ to a script in /etc/init.d/) with following […]