Red Hat Linux 7 Unleashed

Red Hat Linux 7 Unleashed

By William Ball

The Initialization Process and Startup Scripts

This section describes how Linux starts and details the functions of the startup scripts used to prepare your system for use. An important concept to note is the use of various runlevels or Linux system states.

System states grew from the need to separate how the system ran according to the forms of maintenance being performed on a system. This is similar to performing a software or hardware upgrade on older PCs, which generally requires a reboot or shutdown and restart of the computer. These days, however, this practice is partially obviated through new software and hardware technologies. Hot-swappable hardware and software indicates that you can change hard drives, PC cards, or associated software on-the-fly—while the system is running (such as loading or unloading Linux kernel modules with the insmod and rmmod commands).

You'll find a description of various runlevels in the /etc/inittab file or system initialization table. Although Linux differs from other versions of UNIX in several of the levels, Red Hat Intel/Linux mainly uses the following (as listed in /etc/inittab):

#   The runlevels used by RHS are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)

On older versions of Red Hat Linux, you would have found a line just below this listing that looked like this:

id:3:initdefault:

This line, which specifies runlevel 3 and uses the initdefault keyword, tells Linux to go to runlevel 3 (the Full multiuser mode) after loading the kernel (see the inittab man page for other keywords). However, newer versions of Red Hat Linux, where X11 is configured during installation, will most likely now boot to runlevel 5 with an /etc/inittab entry like this:

id:5:initdefault:

This means that Red Hat Linux, if you configure X11, will now boot directly to the X Window System if you choose to boot to a graphical login (using the gdm client, known as the GNOME display manager). See Chapter 5, "Window Managers," for details.

The next section describes these runlevels, including the first startup script in the initialization table, /etc/rc.d/rc.sysinit, or the system initialization script, which is run once at boot time by the init command. It also covers the /etc/rc.d directory structure and what some of these scripts do.

init and /etc/inittab

The init man page states, "init is the father of all processes." Its primary role is to create processes from a script stored in /etc/inittab. Much of how Linux starts its processes after loading the kernel comes from another UNIX, System V. In fact, the Linux init command is compatible with the System V init command, and the startup scripts model that approach. Although init starts as "the last step of the kernel booting," it is the first command that initializes and configures your system for use.

You can see evidence of this process by using the pstree command from the command line of your console or an X11 terminal window. At the command line, type


   # pstree

After you press Enter, you'll see a tree listing of processes somewhat like this (especially if you use a laptop because of the Advanced Power Management and cardmgr PCMCIA manager daemons):

init-+-apmd
     |-atd
     |-2*[automount]
     |-battery_applet
     |-cardmgr
     |-crond
     |-deskguide_apple
     |-gdm-+-X
     |     `-gdm---gnome-session
     |-gmc
     |-gnome-name-serv
     |-gnome-smproxy
...

Although the entire output of pstree is not shown here, you can see that init has spawned the start of the system as the first process, and the parent of all subsequent processes. init works by parsing /etc/inittab and running scripts in /etc/rc.d according to either a default or desired runlevel. Each script can start or stop a service, such as a networking, mail, news, or Web service.

Here's a listing of the /etc/rc.d directory:

init.d/
rc*
rc.local*
rc.sysinit*
rc0.d/
rc1.d/
rc2.d/
rc3.d/
rc4.d/
rc5.d/
rc6.d/

Under the init.d directory, you'll find a number of scripts used to start and stop services. The details about each are not given here, but you should be able to guess at the function of some of them by their names and a short description, as shown in Table 9.1 Note that you may have more or less scripts than shown, because some scripts are part of a service package and will be installed when you install the software.

Table 9.1. Red Hat Linux System Initialization Scripts

Name Description
amd Controls the automount daemon
anacron Scheduling control
apmd Directory contains apmd.init for control of power management and logging
arpwatch Tracks ethernet and Internet protocol address pairings
atd Controls the at (personal scheduling) daemon
autofs Controls the automount filesystem daemon
bootparamd May be used to network boot older Sun workstations
crond Controls the cron system scheduling daemon
dhcpd Controls the Dynamic Host Control Protocol daemon
functions Shell script functions used by init scripts
gated Controls the routing gateway daemon
gpm Controls the console mouse server (console cut-and-paste utility)
halt Controls how shutdowns and reboots are handled
httpd Controls the Apache Web server and HTTP service
identd Controls the user identification server
innd Controls InterNet News System
irda Starts/stops IrDA daemon
isdn Controls ISDN services
kdcrotate Kerberos configuration script
keytable Controls keyboard map loading
killall Utility script used by amd, crond, inet, kerneld, mars-nwe, and the nfs init scripts to kill processes
krb5server Starts/stops Kerberos server
kudzu Hardware probe/config control
ldap Control Directory Access Protocol daemons
linuxconf Utility script for Red Hat's linuxconf tool
lpd Controls print spooling services
mars-nwe Controls Netware-compatible system services
mcserv Controls Midnight Commander remote services
named Controls start and stop of Domain Name Service
netfs Control NFS, SMB, NCP mounts
network Controls starting and stopping system networking
nfs Controls Network Filesystem services
nfslock Controls NFS file-locking
nfsfs Controls mounting of NFS filesystems
nscd Controls the Name Switch Cache daemon
pcmcia Controls Card services for laptops
phhttpd Controls HTTP accelerator
portmap Controls Remote Procedure Call services
postgresql Controls PostgreSQL database daemon
pppoe Starts or stops an ADSL session
pulse Controls clustering monitor
pxe Controls remote-boot server
random Controls random number generation
rarpd Controls RARP daemon
reconfig Manages anaconda's reconfig operation
routed Controls network routing table daemon
rstatd Controls the rpc.statd network kernel statistics daemon
rusersd Controls the rpc.rusersd Network services
rwalld Controls the rpc.rwalld Network Wall services
rwhod Controls the rwhod daemon network rwho services
sendmail Controls mail transport services
single Used by init when Linux is booted to runlevel 1 or single-user administrative mode
smb Controls the Samba smbd and nmbd daemons
snmpd Controls the Simple Network Management Protocol daemon
sound Saves and restores mixer information and levels
squid Controls httpd object caching service
sshd Controls the OpenSSH server
syslog Starts and stops System Logging services
xdm Controls whether to start or stop the X display manager, K display manager, or GNOME display manager for runlevel 5
xfs Starts and stops the X11 font server
xinetd Starts and stops xinetd daemon
xntpd Starts and stops the Network Time Protocol (NTPv3) daemon for time synchronization
ypbind Controls NIS binding services
yppasswdd Controls the YP password server
ypserv Controls Network Information services

In general, each script listed in Table 9.1 is designed to respond to commands of the following form:

script { start|stop|status|restart}

This means that a particular service may be controlled from other programs, depending on the syntax used.

You should also understand that each script in turn may control dozens of other processes or daemons. This is particularly true of the inet and xinetd scripts, used to control various networking services. The xinetd daemon, a new feature of Red Hat Linux, may be used to control nearly two dozen services, such as telnet, wu-ftpd, or POP3 mail server daemons.

/etc/inittab and System States

One of the most important scripts in /etc/inittab is rc.sysinit, the system initialization script. When init parses /etc/inittab, rc.sysinit is the first script found and executed. This differs slightly from other versions of UNIX, which might include the system initialization commands directly in the /etc/inittab file.

However, much like other versions of UNIX, the Red Hat Linux sysinit script performs some or all of the following functions:

That's a lot of work just for the first startup script, but it's only the first step in a number of steps needed to start your system. You've seen that the init command is run after the Linux kernel is loaded. After the rc.sysinit is run by init, init runs rc.local. If you look at the Red Hat Linux rc.local script, you'll see that it gets the operating system name and architecture of your computer and puts it into a file called /etc/issue, which is later used for display at the login prompt.

The next init task is to run the scripts for each runlevel. If you look at the listing of the rc.d directory, you'll see the various rcX.d directories, where X is a number from 0 through 6. If you look at the files under one of these directories, you'll find that each is merely a link to a script under init.d, with an associated name for a particular service. For example, you may find the following under the rc3.d directory:

K01pppoe -> ../init.d/pppoe
K20nfs -> ../init.d/nfs
K20rstatd -> ../init.d/rstatd
K20rusersd -> ../init.d/rusersd
K20rwalld -> ../init.d/rwalld
K20rwhod -> ../init.d/rwhod
K34yppasswdd -> ../init.d/yppasswdd
K45arpwatch -> ../init.d/arpwatch
K84ypserv -> ../init.d/ypserv
K96irda -> ../init.d/irda
S05kudzu -> ../init.d/kudzu
S08ipchains -> ../init.d/ipchains
S10network -> ../init.d/network
S12syslog -> ../init.d/syslog
S13portmap -> ../init.d/portmap
S14nfslock -> ../init.d/nfslock
S20random -> ../init.d/random
S25netfs -> ../init.d/netfs
S35identd -> ../init.d/identd
S40atd -> ../init.d/atd
S45pcmcia -> ../init.d/pcmcia
S50xinetd -> ../init.d/xinetd
S55sshd -> ../init.d/sshd
S56rawdevices -> ../init.d/rawdevices
S60lpd -> ../init.d/lpd
S75keytable -> ../init.d/keytable
S80isdn -> ../init.d/isdn
S80sendmail -> ../init.d/sendmail
S85gpm -> ../init.d/gpm
S90crond -> ../init.d/crond
S90xfs -> ../init.d/xfs
S95anacron -> ../init.d/anacron
S97rhnsd -> ../init.d/rhnsd
S99linuxconf -> ../init.d/linuxconf
S99local -> ../rc.local

Note the S in the front of each name, meaning to start a process or service. Now, if you look at the files under rc0.d, you'll see this:

K00linuxconf -> ../init.d/linuxconf
K01pppoe -> ../init.d/pppoe
K03rhnsd -> ../init.d/rhnsd
K05keytable -> ../init.d/keytable
K10xfs -> ../init.d/xfs
K15gpm -> ../init.d/gpm
K20isdn -> ../init.d/isdn
K20nfs -> ../init.d/nfs
K20rstatd -> ../init.d/rstatd
K20rusersd -> ../init.d/rusersd
K20rwalld -> ../init.d/rwalld
K20rwhod -> ../init.d/rwhod
K25sshd -> ../init.d/sshd
K30sendmail -> ../init.d/sendmail
K34yppasswdd -> ../init.d/yppasswdd
K44rawdevices -> ../init.d/rawdevices
K45arpwatch -> ../init.d/arpwatch
K50xinetd -> ../init.d/xinetd
K60atd -> ../init.d/atd
K60crond -> ../init.d/crond
K60lpd -> ../init.d/lpd
K65identd -> ../init.d/identd
K75netfs -> ../init.d/netfs
K80random -> ../init.d/random
K84ypserv -> ../init.d/ypserv
K86nfslock -> ../init.d/nfslock
K87portmap -> ../init.d/portmap
K88syslog -> ../init.d/syslog
K90network -> ../init.d/network
K92anacron -> ../init.d/anacron
K92ipchains -> ../init.d/ipchains
K95kudzu -> ../init.d/kudzu
K96irda -> ../init.d/irda
K96pcmcia -> ../init.d/pcmcia
K99syslog -> ../init.d/syslog
S00killall -> ../init.d/killall
S01halt -> ../init.d/halt

Notice the K in front of each name, meaning to kill a process or service. If you look under each of the rcX.d directories, you'll see what services or processes are started or stopped in each runlevel. The symbolic links are numbered to run in the proper order and to start or stop services that might be interdependent. (For example, it wouldn't make sense to unmount your filesystem before stopping network file-sharing.) Later in this chapter you'll come back to some of the rc.sysinit tasks because some of the error-checking done when starting up can help pinpoint problems with your system. For now, however, the following section explains the runlevels and what basically happens in each.

Runlevel 0: /etc/rc.d/rc0.d

As you can see from the previous directory listing, this runlevel starts the shutdown sequence. Each script is run in the order listed. Some of the tasks run include

As shown in this section and discussed later in this chapter, some important things are done during a shutdown that involve your computer, its services, and its filesystems. Although Linux is a robust operating system with system-checking safeguards, executing a proper shutdown is essential to maintaining the integrity of your computer's hard drive as well as any Linux volumes or partitions.

Runlevel 1: /etc/rc.d/rc1.d

Runlevel 1 is the single-user mode, or administrative state, traditionally used by sysadmins while performing software maintenance. No one else can log in during this mode, and networking is turned off, although necessary filesystems are mounted. (Others can be mounted manually at the command-line prompt but then must be specifically unmounted before rebooting.)

If you use the LILO or LOADLIN bootloaders, you can boot Linux directly to this runlevel by passing a kernel argument or option on the LOADLIN command line or at the LILO boot: prompt. For LILO users, the argument generally takes the form

boot: linux single

After pressing Enter, Linux will boot to runlevel 1. You could also use the option 0 (numeral 0) instead of the single keyword like this:

boot: linux 0

Runlevel 2: /etc/rc.d/rc2.d

Runlevel 2 is the multiuser state. Networking is enabled, although NFS is disabled. This may be a good choice if you only use Red Hat Linux as a standalone desktop operating system for your PC.

Runlevel 3: /etc/rc.d/rc3.d

Runlevel 3 used to be the default runlevel specified as the first line in /etc/inittab; however, you may find that newer Red Hat Linux distributions use runlevel 5 as the default to boot directly to X and a display manager for logins. If you choose to use runlevel 3, you'll find that remote file-sharing is enabled, along with most other desired services.

Runlevel 4: /etc/rc.d/rc4.d

The runlevel 4 directory is set up so that you can define your own runlevel (and is, in fact, an exact copy of the settings for runlevel 5, enabling multiuser mode, networking, and X11). Note that in /etc/inittab, runlevel 4 is flagged as "unused." As in other versions of UNIX, if you want to define your own runlevel, here's where you can add the appropriate links, with directions to selectively start or stop processes.

Runlevel 5: /etc/rc.d/rc5.d

Runlevel 5 is used as the default runlevel when booting Linux with an X11 display manager. Many networking services are enabled by default.

Runlevel 6: /etc/rc.d/rc6.d

Runlevel 6 is the reboot runlevel. The contents of this directory contain links similar to those in runlevel 0, but logic in the halt script under init.d determines whether the system is being shut down or rebooted.

Keeping track of which process is started or stopped in which runlevel can be difficult. In the next section you'll see one more reason why using Red Hat Linux can make your system administration tasks easier.

Share ThisShare This

Informit Network