• No results found

Note: Once the system has started, you can switch runlevels with init runlevel or telinit runlevel

In document IUTXE_lx30stud (Page 57-63)

- S - Single-user mode (no scripts run) (SUSE) - 1 - Single-user mode (some scripts run) - 2 - Local multiuser without network - 3 - Full multiuser with network - 4 - Not used

- 5 - Full multiuser with network and xdm (GUI) - 6 - System reboot

The runlevels are defined in /etc/inittab. For example:

# cat /etc/inittab

Each run level has a set of scripts associated with it in the directory structure

/etc/init.d/rc<X>.d (SUSE) or /etc/rc<X>.d (Red Hat, Fedora), where X is the run level.

In the example, runlevel 3 would cause the script /etc/rc.d/rc to execute scripts in the /etc/rc.d/rc.3 directory structure.

Default runlevel

The default runlevel is specified in the /etc/inittab file. The entry id: identifies the default runlevel. For example:

# grep id /etc/inittab id:5:initdefault:

The default runlevel for the system in the example will be runlevel 5.

Run-level determination

The current system run level can be determined by using either of the following

Switching runlevels

Switching runlevels can be accomplished by using either the init or telinit commands. For example, to change the runlevel of the system to runlevel 1:

# runlevel N 5

# init 1

# runlevel 5 1

In the example, by using the runlevel command, you can identify the current runlevel state before and after the init command was issued.

Figure 2-11. /etc/inittab (RHEL/Fedora/SLES) LX036.0

Notes:

Introduction

The visual shows the most important lines of the /etc/inittab file. Because there are minor differences in RHEL/Fedora and SLES /etc/inittab files, they are shown side by side.

Default runlevel

As mentioned earlier, the entry id: identifies the default runlevel unless it was specified during the boot process. In the example shown in the visual, the default runlevel is 3.

© Copyright IBM Corporation 2009

# Run gettys in standard runlevels 1:2345:respawn:/sbin/mingetty tty1

# Run gettys in standard runlevels 1:2345:respawn:/sbin/mingetty

The second entry directs init to always run the /etc/rc.d/rc.sysinit (RHEL/Fedora) or /etc/init.d/boot (SLES) script. This script does a number of important low-level tasks, such as:

- Activating swap spaces - Setting the hostname

- Checking the root filesystem for errors, and remounting it read-write - Turning on quota support

- Loading important kernel modules

- Checking all other filesystems and mounting them

- Deleting various lockfiles which may have been left over from a crash - Enabling the clock

Defined runlevels

The next set of lines tells init to run the /etc/rc.d/rc or /etc/init.d/rc in runlevels 0 through 6, with the runlevel as a parameter. We will look at this script in the next visual.

Key sequence trap

After that, the trap for the Ctrl-Alt-Delete three-finger salute is set. This means that if you press this key combination, the shutdown command is executed, effectively rebooting your system.

Terminal getty’s

Finally, six gettys are started on tty1 through tty6. This means that there are six virtual terminals configured, allowing you to log in as different users six times. These six virtual terminals can be reached by pressing Alt-F1 through Alt-F6.

prefdm

The last command, which is only run in runlevel 5, starts the prefdm command, which in turn starts xdm, gdm or kdm. These programs present a graphical login screen. This is unique to RHEL/Fedora: SUSE starts this through a regular init script (covered in the next few visuals).

Note: Some commands have the prefix once, some have wait as prefix, and others have respawn. This identifies what init should do after it has started the command:

- wait means that init should wait for the command to finish before it is allowed to go on with the rest of the init sequence.

- once means that init is allowed to go on with the init process even before the command has finished.

- respawn means that init should start this process, put it in the background, and monitor its existence. Once the process dies, init should start a new one. This is commonly used for login processes because a new login screen will then

automatically appear, even if the user manages to kill off all its processes.

Figure 2-12. Starting services (System V init style) LX036.0

Notes:

Introduction

The rc script is a very important script. Although small, it is responsible for starting almost all services that are active in the runlevel that was specified as parameter.

What this script basically does is the following:

- It changes to the directory /etc/rc.d/rc<runlevel>.d2

- In this directory, it makes a list of all scripts that start with a K, sorts this list on the two digits after the K, and executes these scripts with the stop parameter.3

- Then, it makes a list of all scripts that start with an S, sorts it, and executes them with the start parameter.

2 This directory is a symlink to /etc/init.d/rc<runlevel>.d in SLES

3 Obviously, kill scripts are not relevant when booting straight into a runlevel. It is possible, however, to change runlevels in a live system by running the command init <new runlevel>. In that case, it might be necessary to stop services, for instance when switching from a multiuser to a single-user runlevel.

© Copyright IBM Corporation 2009

In document IUTXE_lx30stud (Page 57-63)

Related documents