Some more notes on Kamikaze boot sequence

1. Introduction

There is very little documentation on the boot sequence of Kamikaze, so I'm leaving my notes here in case someone is interested.

2. NOTES

These notes are based on Kamikaze trunk svn as downloaded in August 2008

These are continuing notes from Kamikaze Boot Sequence Notes

3. Common Functions Scripts

Since there are common functions used by many of the scripts in Kamikaze (not just for starting/shutdown/reboot), let's see what's there.

3.1. /etc/functions.sh

This shell script is nothing more than a repository of common functions and variables that make shell scripting in Kamikaze easier. Here are the relevant parts of the script:

3.1.1. Defined Variables

3.1.2. Defined Functions

3.2. /lib/config/uci.sh

This script contains wrapper functions for making it easier to manipulate configuration files as used by UCI

3.2.1. Defined Variables

3.2.2. Defined Functions

3.3. /etc/rc.common

This shell script is some common functions that are used for the startup/shutdown sequences.

3.3.1. Placeholder Functions

In most cases, these functions used for boot scripts that don't have them defined due to not being needed.

For example, the /etc/init.d/umount boot script only needs to define the stop() function since it's only purpose is to cleanly unmount storage media before the system halts/reboots.

3.3.2. Defined Functions

4. Boot Scripts

The boot scripts follow the SysVInit style ( similar to RedHat(tm) ).

The script files are located in the /etc/init.d directory. The actual magic occurs via links to these scripts that are located under the /etc/rc.d directory.

Initialization scripts are executed at both power-up and shutdown. The main difference is when they are called and what options are passed to them.

4.1. Design Of Boot Scripts

The boot script itself has a specific layout in order to work properly. The main requirements are:

4.2. Boot Script Naming

NOTE: Script naming convention for /etc/rc.d scripts is noted here for explanation only. There's a helper function in the /etc/rc.common file that handles the actual link creation/removal for the /etc/rc.d directory.

A basic description of the startup/shutdown scripts directories are /etc/init.d contains the actual scripts, and /etc/rc.d contains a link to the file in /etc/init.d but the name includes either an "S" (for "START") or "K" (for "KILL"), followed by a sequence number, then the rest of the script name.

The format of the script name is "X##nnnn" where:

For example - the script file /etc/init.d/network is the script that brings up/takes down network interfaces and defines the variables START=40 and STOP=40. The relevant startup link is /etc/rc.d/S40network and the shutdown link is /etc/rc.d/K40network.

4.2.1. /etc/init.d/network Script

For this example, I will use the /etc/init.d/network script since it is called at both power-up and shutdown/reboot.

01.  #!/bin/sh /etc/rc.common
02.  # Copyright (C) 2006 OpenWrt.org
03. 
04.  START=40
05.  STOP=40
06. 
07.  boot() {
08.      setup_switch() { return 0; }
09.
10.     include /lib/network
11.     setup_switch
12.     [ -s /etc/config/wireless ] || \
13.          /sbin/wifi detect > /etc/config/wireless
14.     /sbin/wifi up
15. }
16.
17. start() {
18.      ifup -a
19.      /sbin/wifi up
20. }
21.
22. restart() {
23.      setup_switch() { return 0; }
24.
25.      include /lib/network
26.      setup_switch
27.      ifup -a
28.      /sbin/wifi up
29. }
30.
31. stop() {
32.      ifdown -a
33. }
34.


CategoryHowTo

OpenWrtDocs/OpnenWrtDocs/KamikazeBootScriptsHowTo (last edited 2008-08-22 19:44:07 by alisonken1)

Almost all of these pages are editable, create an account and click the edit (Edit) button at the top of the page.