Subsections

8.7 Boot, Reboot, Dialin And Hangup Under fli4l

8.7.1 Boot Concept

FLI4L 2.0 should offer a clean install on a hard disk or a CompactFlash (TM) media, but also an installation on a Zip medium or the creation of a bootable CD-ROM should be possible. In addition, the hard drive version should not be fundamentally different from the one on an installation disk8.10.

These requirements have been implemented by making it possible to move the files of the opt.img archive from the previous RAM disk to another medium, be it a partition on a hard disk or a CF medium. This second volume is mounted to /opt and only symbolic links are created from there to the rootfs. The resulting layout in the root file system then corresponds to the one unpacked in the opt directory of the fli4l distribution with one exception - the files prefix is not applicable. The file opt/etc/rc is then found directly under /etc/rc, opt/files/bin/busybox under /bin/busybox. It can be ignored that these files may be only links to a directory mounted read only as long as you do not want to modify them. If you want to do this, you have to make the files writable before by using mk_writable (see below).

8.7.2 Start And Stop Scripts

Scripts intended to be executed on system boot are located in the directories opt/etc/boot.d/ and opt/etc/rc.d/ and will also get executed in this sequence. Furthermore, scripts executed on shutdown are to be found in opt/etc/rc0.d/.


Important: These script must not contain an ``exit'', because no separate process is created for their execution. This command would lead to a premature ending of the boot process!

8.7.2.1 Start Scripts in opt/etc/boot.d/

Scripts located in this directory are executed at first. They mount the boot volume, parse the config file rc.cfg located on the boot medium and unpack the opt archive. Depending on the boot type these scripts are more or less complex and do the following things:

To make the scripts aware of the fli4l configuration, the configuration file /etc/rc.cfg is also integrated in the Rootfs archive. The configuration variables in this file are parsed by the start scripts in opt/etc/boot.d/. After mounting the boot volume /etc/rc.cfg is replaced by the configuration file there, so that the the current configuration of the boot volume is available for startup scripts in opt/etc/rc.d/ (see below). 8.11

8.7.2.2 Start Scripts in opt/etc/rc.d/

Commands that are executed at every start of the router can be stored in the directory opt/etc/rc.d/. The following conventions apply:

  1. Name conventions:

        rc<three-digit number>.<Name of the OPT>
    

    The scripts are started in ascending order of the numbers. If multiple scripts have the same number assigned, they will be sorted alphabetically at that point. In case that the start of a package is dependant on another one, this is the determined by the number.

    Here's a general outline which numbers should be used for which tasks:


    Number Task
    000-099 Base system (hardware, time zone, file system)
    100-199 Kernel modules (drivers)
    200-299 External connections (PPPoE, ISDN4Linux, PPtP)
    300-399 Network (Routing, Interfaces, Packet filter)
    400-499 Server (DHCP, HTTPD, Proxy, a.s.o.)
    500-900 Any
    900-997 Anything causing a dialin
    998-999 reserved (please do not use!)

  2. These scripts must contain all functions changing the RootFS, ie. creating of a directory /var/log/lpd.

  3. These scripts shall not contain writing to files that could be part of the opt archive, because these files could be located on a volume mounted in read-only mode. If you have to modify such a file, you have to make it writeable before by using the function mk_writable (see below). This will create a writable copy of the file in the RootFS if needed. If the file is already writable the call of mk_writable will have no effect.


    Important: mk_writable has to be applied directly to files in RootFS, not indirectly via the opt directory. If, for example, you want to modify /usr/local/bin/foo, the function mk_writable has to be called with the argument /usr/local/bin/foo.

  4. Before executing the actual commands these scripts have to check for the associated OPT really being active. This is usually done by a simple if-case:

        if [ "$OPT_<OPT-Name>" = "yes" ]
        then
            ...
            # Start OPT here!
            ...
        fi
    

  5. For easier debugging the scripts should be enclosed in begin_script and end_script:

        if [ "$OPT_<OPT-Name>" = "yes" ]
        then
            begin_script FOO "configuring foo ..."
            ...
            end_script
        fi
    

    Debugging of start-scripts may be activated simply via FOO_DO_DEBUG='yes'.

  6. All configuration variables are available to the scripts in direct. Explanations how to access configuration variables in scripts can be found in the section ``Working with configuration variables''.

  7. The path /opt may not be used for storing OPT data. If in need of additional file space you should enable the user to define a suitable location by using a configuration variable. Depending on the type of data to be stored (persistent or transient data) different default assignments should be used. A path under /var/run/ makes sense for transient data, while for persistent data it is advised to use the function map2persistent combined with a suitable configuration variable.

8.7.2.3 Stop Scripts in opt/etc/rc0.d/

Each machine must be shut down or restarted from time to time. It is perfectly possible that you have to perform operations before the computer is shut down or restarted. To shut down and restart the commands ``halt'' or ``reboot'' are used. These commands are also invoked when the corresponding buttons in IMONC or the Web GUI are clicked.

All stop scripts can be found in the opt/etc/rc0.d/. The file names have to be created using the same rules as for the scripts. They are as well executed in ascending order of numbers.

8.7.3 Helper Functions

/etc/boot.d/base-helper provides a number of different functions that can be used in Start- and other scripts. They contian support for debugging, loading of kernel modules, or message output. The functions are listed and explained in short below

8.7.3.1 Script Control

begin_script <Symbol> <Message>:
Output of a message and activation of script debugging by calling set -x, if <Symbol>_DO_DEBUG is set to ``yes''.

end_script:
Output of an end-message and deactivation of debugging if it was activated with begin_script. For each begin_script call a corresponding end_script call has to exist (and vice versa).

8.7.3.2 Loading Of Kernel Modules

do_modprobe [-q] <Modul> <Parameter>*:
Loads a kernel module including its parameters (if needed) while resolving its module dependencies. The parameter ``-q'' prevents error messages to be written to the console and to the boot log in case of failure. The function returns 0 for success and another value in case of error. This enables you to create code for handling failures while loading kernel modules:

    if do_modprobe -q acpi-cpufreq
    then
        # no CPU frequency scaling via ACPI
        log_error "CPU frequency scaling via ACPI not available!"
        # [...]
    else
        log_info "CPU frequency scaling via ACPI activated."
        # [...]
    fi

do_modrobe_if_exists [-q] <Module path> <Module> <Parameter>*:

Checks if the module /lib/modules/<Kernel-Version>/<Module path>/<Module> exists and, if so, invokes do_modprobe.


Important: The module has to exist exactly by this name, no aliases may be used. When using an alias do_modprobe will be called immediately.

8.7.3.3 Messages And Error Handling

log_info <Message>:
Logs a message to the console and to /bootmsg.txt. If no message is passed as a parameter log_info reads the default input. The function always returns 0.

log_warn <Message>:
Logs a warning message to the console and to /bootmsg.txt, using the string WARN: as a prefix. If no message is passed as a parameter log_warn reads the default input. The function always returns 0.

log_error <Message>:
Logs an error message to the console and to /bootmsg.txt, using the string ERR: as a prefix. If no message is passed as a parameter log_warn reads the default input. The function always returns a non-zero value.

set_error <Message>:
Output of an error message and setting of an internal error variable which can be checked later via is_error.

is_error:
Clears the internal error variable and returns true if it was set before via set_error.

8.7.3.4 Network Functions

translate_ip_net <Value> <Variable name> [<Result variable>]:

Replaces symbolic references in parameters. At the moment the following translations are supported:
*.*.*.*, none, default, pppoe
will not be translated
any
will be replaced by 0.0.0.0/0
dynamic
will be replaced by the IP address of the router which represents the Internet connection
IP_NET_x
will be replaced by the network found in the configuration
IP_NET_x_IPADDR
will be replaced by the IP address found in the configuration
IP_ROUTE_x
will be replaced by the routed network found in the configuration
@<Hostname>
will be replaced by the Hosts IP address specified in the configuration

The result of the translation is stored in the variable whose name is passed in the third parameter, if this parameter is missing, the result is stored in the variable res. The variable name that is passed in the second parameter is used only for error messages if the translation fails, to enable the caller to pass the source of the value to be translated. In case of failure a message like

    Unable to translate value '<Value>' contained in <Variable name>.

will be printed.

The return value is 0 in case of success, and unequal to zero in case of errors.

8.7.3.5 Miscellaneous

mk_writable <File>:
Ensures that the given file is writable. If the file is located on a volume mounted in read-only mode and is only linked to the file system via a symbolic link, a local copy will be created which is then written to.

unique <List>:
Removes duplicates from a list passed. The result is returned in the variable list.

8.7.4 ttyI Devices

For ttyI devices (/dev/ttyI0 .../dev/ttyI15) used by the ``modem emulation'' of the ISDN card a counter exists to avoid conflicts between multiple packages using these devices. For this purpose the file /var/run/next_ttyI is created on router start which can be queried and incremented by the OPTs. The following example script can query this value, increment it by one and export it again for the next OPT.

    ttydev_error=
    ttydev=$(cat /var/run/next_ttyI)
    if [ $ttydev -le 16 ]
    then                                    # ttyI device available? yes
        ttydev=$((ttydev + 1))              # ttyI device + 1
        echo $ttydev >/var/run/next_ttyI    # save it
    else                                    # ttyI device available? no
        log_error "No ttyI device for <Name of your OPT> available!"
        ttydev_error=true                   # set error for later use
    fi

    if [ -z "$ttydev_error" ]               # start OPT only if next tty device
    then                                    # was available to minimize error
        ...                                 # messages and minimize the
                                            # risk of uncomplete boot
    fi

8.7.5 Dialin And Hangup Scripts

8.7.5.1 General

After dialin resp. hangup of a dial-up connection the scripts placed in /etc/ppp/ are executed. OPTs may store actions here that have to be executed after connecting resp. hanging up of a connection. The name scheme for the files is as follows:


ip-up<three-digit number>.<OPT-Name>
ip-down<three-digit number>.<OPT-Name>

ip-up scripts will be excuted after establishing and ip-down scripts after hangig up of the connection.


Important: In ip-down scripts no actions may be taken that lead to another dialin because this would create a permanent-online condition not desired for users without a flatrate.


Important: Since no separate process is created for these scripts, they may not invoke ``exit'' as well!

Hint: If a script wants to check for ip-up scripts being executed the variable ip_up_events may be sourced from rc400 and up. If it is set to ``yes'' dialup-connections exist and ip-up scripts will be executed. No dialup-connections are configured if it is set to ``no'' and ip-up scripts will not get executed. There is an exeception to this rule: If an Ethernet router is configured without dialup-connections but a default-Route (0.0.0.0/0) exists, ip-up scripts will get executed only once at the end of the boot process. (And as well the ip-down scripts on rooter shutdown.)

8.7.5.2 Variables

Due to the special call concept of the ip-up and ip-down scripts the following variables apply:


real_interface the real interface, ie. ppp0, ippp0, ...
interface the IMOND interface, ie. pppoe, ippp0, ...
tty terminal connected, may be empty!
speed connection speed, for ISDN ie. 64000
local own IP address
remote IP address of the Point-To-Point partner
is_default_route specifies if the current ip-up/ip-down is for the interface of the default route (may be ``yes'' or ``no'')

8.7.5.3 Default Route

As of version 2.1.0 ip-up/ip-down scripts are executed for all connections, not only for the interface of the default route. To emulate the old behaviour you have to include the following in ip-up and ip-down scripts:

    # is a default-route-interface going up?
    if [ "$is_default_route" = "yes" ]
    then
        # actions to be taken
    fi

Of course, the new behaviour can also be used for specific actions.



Footnotes

... disk8.10
Originally fli4l could be operated from a single floppy disk. This is no longer supported since it became too big in file size.
... below).8.11
Normally, these two files are identical. Discrepancies are possible only if the configuration file on the boot volume was edited manually, for example to modify the configuration later on without the need to rebuild the fli4l archives.
© 2001-2019 The fli4l-Team - 28 April 2019