Chapter 2. System Startup

Table of Contents

2.1. Customising the Boot Process
2.1.1. Overview of init
2.1.2. Runlevels
2.1.3. Starting Local scripts
2.2. System Recovery
2.2.1. Overriding the INIT stage
2.2.2. Errors at the end of the kernel stage
2.2.3. Misconfigured Bootloaders
2.2.4. Bootloader Kernel Parameters
2.2.5. Troubleshooting LILO
2.3. Customised initrd
2.3.1. The mkinitrd script

Customising the boot process involves understanding how startup script are called. The chapter also describes common problems that arise at different points during the booting process as well as some recovery techniques. Finally we focus our attention on the initial ram disk (or initial root device) initrd stage of the booting process. This will allow us to make decisions as to when new initial ram disks need to be made.

2.1. Customising the Boot Process

2.1.1. Overview of init

In order to prevent processes run by users from interfering with the kernel two distinct memory areas are defined. These are referred to as kernel space memory and user space memory. The init process is the first program to run in user-space.

init is therefore the parent of all processes. The init program's configuration file is /etc/inittab.

2.1.2. Runlevels

Runlevels determine which processes should run together. All processes that can be started or stopped at a given runlevel are controlled by a script (called an init script or an rc script) in /etc/rc.d/init.d (or /etc/init.d in some systems.

List of rc scripts on a typical system

anacron    halt       kudzu    ntpd        rusersd   syslog     ypxfrd
apmd       identd     lpd      portmap     rwalld    vncserver
atd        ipchains   netfs    radvd       rwhod     xfs
autofs     iptables   network  random      sendmail  xinetd
crond      kdcrotate  nfs      rawdevices  single    ypbind
functions  keytable   nfslock  rhnsd       snmpd     yppasswdd
gpm        killall    nscd     rstatd      sshd      ypserv

Selecting a process to run or be stopped in a given runlevel is done by creating symbolic links in the /etc/rc.d/rcN.d/ (or /etc/rcN.d/ on some systems) directory, where N is a runlevel.

Example 2.1. Selecting httpd process for runlevel 3

ln -s  /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S85httpd

Notice that the name of the link is the same as the name of the process and is preceded by an S for start and a number representing the order of execution.

Example 2.2. Stopping httpd process for runlevel 3

rm /etc/rc.d/rc3.d/S85httpd
ln -s  /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/K15httpd

This time the name of the link starts with a K for kill to make sure the process is stopped when switching from one runlevel to another.

2.1.3. Starting Local scripts

We want to run a script at a given run level. Our script will be called printtotty10 and will simply print the message given as an argument to /dev/tty10.

/bin/printtotty10

#!/bin/bash
echo $1 > /dev/tty10
  1. One way to have the script started at a specific run level is to add a line in /etc/inittab like

    pr10:3:once:/bin/printtotty10 Printtotty was started in inittab
    

    This is not always the best way to do this. What if many scripts need to be started? The inittab file would look messy.

  2. We can write a custom rc-script. We follow the usage to call the script the same name as the actual tool we want to startup.

    /etc/rc.d/init.d/printtotty10

    #!/bin/sh
    # chkconfig: 345 85 15
    # description: This line has to be here for chkconfig to work ... \
    #The script will display a message on /dev/tty10
    #First source some predefined functions such as echo_success()
    ./etc/rc.d/init.d/functions
    
    start()  {
            echo -n  "Starting printtotty10"
            /bin/printtotty10 "printtotty10 was started with an rc-script "
            echo_success
            echo
    }
    
    
    stop() {
            echo -n "Stopping custom-rc"
            /bin/printtotty10 "The custom script has stopped"
            echo_success
            echo
    }
    case "$1" in
      start)
            start;;
      stop)
            stop;;
    esac
    exit 0
    
  3. The printtotty10 script can be started at boot time by placing the command in /etc/rc.d/rc.local. The rc.local script is the last rc-script to be run.

    [Note]Note

    When setting up a linux server as a router it is possible to switch on ip-forwarding at boot time by adding the following line to rc.local:

    echo 1 > /proc/sys/net/ipv4/ip_forward 
    

    However it is better to use the sysctl mechanism to switch ip-forwarding on every time the network interface is started. This is done by adding the following line to /etc/sysctl.conf:

    net.ipv4.ip_forward = 1