System Initialization: BSD Versus System V Initialization

team bbl


System initialization starts where the kernel bootup ends. The first program that the kernel runs is the init process. The init process reads the system initialization table (/etc/inittab) to see how various daemons need to be initialized and started. This section examines how system initialization works in Linux.

The various Linux distributions have adopted two system initialization styles. Red Hat and Debian use the System V initialization type. Others, such as Slackware, use the BSD style.

The Filesystem Hierarchy Standard (FHS) v2.0 for Linux states that either BSD- or System V-style initialization is acceptable. The standard stopped short, however, of outlining exactly where the rc scripts would go, except to say that they would be below /etc. Future revisions to the standard might provide further guidance.

Under system initialization, the biggest difference between BSD and System V is the init scripts. With BSD style, all daemons are started essentially by only a few scripts. For example, the init process in Slackware, which adopts the BSD style, runs the system script (/etc/rc.d/rc.S) to prepare the system. The rc.S file enables the system's virtual memory, mounts necessary file systems, cleans up certain log directories, initializes Plug and Play devices, loads kernel modules, configures PCMCIA devices, and sets up serial ports. The local script (rc.local) is available for system administrators to tailor to the specific system on which it is running. The system and local scripts can, in turn, call other scripts to accomplish their objectives, but they are called by the init process sequentially.

Many other Linux distributions make use of System V style instead of the BSD style. Unlike the BSD style, the System V scripts are independent, stand-alone initialization scripts. They make use of runlevels that correspond to different groups of processes or tasks to be executed. The scripts are run from runlevels 0 to 6 by default, even though several runlevels are not used. In other words, each runlevel is given a subdirectory for init scripts that allows for maximum flexibility in initializing the system and necessary daemons. The BSD style, by having only a few scripts to start everything, does not allow for the kind of flexibility System V brings. It does, however, make things easier to find.

It should be noted that, even though Slackware adopts the BSD-style system initialization, it does provide System V initialization compatibility. In fact, many Linux distributions use the same init binary, so the difference is not that great between various Linux distributions when it comes to system initialization.

Initialization Table (/etc/inittab)

As mentioned earlier, the system initialization table (/etc/inittab) specifies to the init process how to initialize and start various daemons during system bootup. Comments in /etc/inittab are preceded by # and are skipped over by the init process. Non-comment lines in /etc/inittab have the following format:

 id:runlevel:action:process  

  • id is a unique identifier for the rest of the line. It is typically limited to two characters.

  • runlevel can be null or contain a valid runlevel, which defines the state that the system will be running in. Runlevels are essentially groups of processes or actions to be executed during system initialization. They can be used as follows:

    • Runlevel 0: System halt

    • Runlevel 1: Maintenance mode (single-user mode)

    • Runlevel 6: System reboot

    • Runlevels 25: Can be customized

  • action can be several different commands, the most common being respawn, but it can also be any one of the following: once, sysinit, boot, bootwait, wait, off, ondemand, initdefault, powerwait, powerfail, powerokwait, ctrlaltdel, or kbrequest.

  • process is the specific process or program to be run.

Now let's see how the system initialization table (/etc/inittab) works in BSD and System V flavors. We'll use Slackware Linux as an example for BSD style and Red Hat for System V style.

BSD inittab (Slackware)

Slackware Linux uses the BSD-style file layout for its system initialization files. All of the system initialization files are stored in the /etc/rc.d directory. Remember, the /etc/rc.d/rc.S script is called by the init process to enable the system's virtual memory, mount necessary file systems, clean up certain log directories, initialize Plug and Play devices, and then call other scripts in the /etc/rc.d directory to complete other work. This includes loading kernel modules (/etc/rc.d/rc.modules), configuring PCMCIA devices (/etc/rc.d/rc.pcmcia), and setting up serial ports (/etc/rc.d/rc.serial).

After system initialization is complete, init moves on to runlevel initialization. As described previously, a runlevel describes the state in which your machine will be running. The files listed in Table 1.2 define the different runlevels in Slackware Linux.

Table 1.2. Runlevels in Slackware Linux

rc.0

Halt the system (runlevel 0). By default, this is symlinked to rc.6.

rc.4

Multiuser startup (runlevel 4), but in X11 with KDM, GDM, or XDM as thelogin manager.

rc.6

Reboot the system (runlevel 6).

rc.K

Start up in single-user mode (runlevel 1).

rc.M

Multiuser mode (runlevels 2 and 3), but with the standard text-based login. This is the default runlevel in Slackware.


Runlevels 2, 3, and 4 start up the network services if enabled. The files listed in Table 1.3 are responsible for the network initialization.

Table 1.3. Network Initialization

rc.inet1

Created by netconfig, this file is responsible for configuring the actual network interface.

rc.inet2

Runs after rc.inet1 and starts up basic network services.

rc.atalk

Starts up AppleTalk services.

rc.httpd

Starts up the Apache web server.

rc.samba

Starts up Windows file- and print-sharing services.

rc.news

Starts up the news server.

rc.sysvinit

The rc.sysvinit script searches for any System V init scripts in /etc/rc.d and runs them if the runlevel is appropriate. This is useful for certain commercial software packages that install System V init scripts and scripts for BSD-style init.


In addition to the rc scripts listed here, rc.local contains specific startup commands for a system. rc.local is empty after a fresh install because it is reserved for local administrators. This script is run after all other initialization has taken place.

Sys V inittab (Red Hat)

Under Red Hat, all the system initialization scripts are located in /etc/rc.d. Because Red Hat uses the System V style, the /etc/rc.d subdirectory has even more subdirectories, one for each runlevel: rc0.d to rc6.d and init.d. Within the /etc/rc.d/rc#.d subdirectories (where # is replaced by a single-digit number) are links to the master scripts stored in /etc/rc.d/init.d. The scripts in init.d take an argument of start, stop, reload, or restart.

The links in the /etc/rc.d/rc#.d directories all begin with either an S or a K for start or kill, respectively, a number that indicates a relative order for the scripts, and the script name (generally, the same name as the master script found in init.d to which it is linked). For example, S20lpd runs the script lpd in init.d with the argument start, which starts up the line-printer daemon.

The nice part about System V initialization is that it is easy for root to start, stop, restart, or reload a daemon or process subsystem from the command line, simply by calling the appropriate script in init.d with the argument start, stop, reload, or restart. For example, the script lpd can be called from the command line, as follows:

 /etc/rc.d/init.d/lpd start 

Red Hat defines the runlevels as follows (the default runlevel is 3):

  • Runlevel 0: System halt

  • Runlevel 1: Single-user mode

  • Runlevel 2: Multiuser mode (the same as runlevel 3, but without networking)

  • Runlevel 3: Full multiuser mode

  • Runlevel 4: Unused

  • Runlevel 5: X11

  • Runlevel 6: System reboot

When not called from a command line with an argument, the rc script parses the command line. For example, if it is running K20lpd, it runs the lpd init script with a stop argument. When init has followed the link in /etc/inittab to rc.d/rc3.d, it begins by running all scripts that start with a K in numerical order from lowest to highest, then likewise for the S scripts. This ensures that the correct daemons are running in each runlevel and are stopped and started in the correct order. For example, the sendmail or bind/named (Berkeley DNS or Domain Name Service daemon) cannot be started before networking is started. In contrast, the BSD-style Slackware starts networking early in the rc.M script. As a result, you must always be cognizant of the order of the entries when modifying Slackware startup scripts.

All of the initialization scripts are simple ASCII text files that can be easily modified with vi or any text editor. As noted earlier, many Linux distributions use the same init binary, so the difference is not that great between various Linux distributions when it comes to system initialization. In fact, symbolic links can be added to make a BSD-style initialization look like a System V-style initialization, and vice versa.

    team bbl



    Performance Tuning for Linux Servers
    Performance Tuning for Linux Servers
    ISBN: 0137136285
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net