Using Init and etcinittab

Once the kernel has loaded and mounted the device where the root directory of your server is stored, the init process is the next to load. This process is the mother of all processes, as you will learn later in this book. init is also responsible for everything that happens in the system initialization procedure from now on. To do its work, init reads its configuration file, /etc/inittab. From there, it learns what else it needs to do. Two of the major tasks handled by init are the initial boot procedure and after that the starting of services. Because they are so important, the next two sections in this chapter are dedicated to those subjects. In this section, I'll cover everything else. In Listing 10-2, you can find the contents of /etc/inittab as it is created after a default installation of SUSE Linux Enterprise Server.

Listing 10-2. /etc/inittab #

# /etc/inittab

# Copyright (c) 1996-2002 SuSE Linux AG, Nuernberg, Germany. All rights reserved.

# Author: Florian La Roche, 1996

# Please send feedback to http://www.suse.de/feedback

# This is the main configuration file of /sbin/init, which

# is executed by the kernel on startup. It describes what

# scripts are used for the different run-levels.

# All scripts for runlevel changes are in /etc/init.d/.

# This file may be modified by SuSEconfig unless CHECK_INITTAB

# in /etc/sysconfig/suseconfig is set to "no"

# The default runlevel is defined here id:5:initdefault:

# First script to be executed, if not booting in emergency (-b) mode si::bootwait:/etc/init.d/boot

# /etc/init.d/rc takes care of runlevel handling

System halt (Do not use this for initdefault!) Single user mode

Local multiuser without remote network (e.g. NFS) Full multiuser with network Not used

Full multiuser with network and xdm System reboot (Do not use this for initdefault!)

is is is is is is is

# runlevel 0

# runlevel 1

# runlevel 2

# runlevel 3

# runlevel 4

# runlevel 5

# runlevel 6

l0:0:wait:/etc/init.d/rc 0 l1:1:wait:/etc/init.d/rc 1 l2:2:wait:/etc/init.d/rc 2 l3:3:wait:/etc/init.d/rc 3 #l4:4:wait:/etc/init.d/rc 4 l5:5:wait:/etc/init.d/rc 5 l6:6:wait:/etc/init.d/rc 6

# what to do in single-user mode ls:S:wait:/etc/init.d/rc S

:S:respawn:/sbin/sulogin

# what to do when CTRL-ALT-DEL is pressed ca::ctrlaltdel:/sbin/shutdown -r -t 4 now

# special keyboard request (Alt-UpArrow)

# look into the kbd-0.90 docs for this kb::kbrequest:/bin/echo "Keyboard Request -- edit /etc/inittab to let this work.

# what to do when power fails/returns pf::powerwait:/etc/init.d/powerfail start pn::powerfailnow:/etc/init.d/powerfail now #pn::powerfail:/etc/init.d/powerfail now po::powerokwait:/etc/init.d/powerfail stop

# for ARGO UPS

sh:12345:powerfail:/sbin/shutdown -h now THE POWER IS FAILING

# getty-programs for the normal runlevels

# <id>:<runlevels>:<action>:<process>

# The "id" field MUST be the same as the last

# characters of the device (after "tty"). 1:2345:respawn:/sbin/mingetty --noclear tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5

6:2345:respawn:/sbin/mingetty tty6

#S0:12345:respawn:/sbin/agetty -L 9600 ttyS0 vt102 #

# Note: Do not use tty7 in runlevel 3, this virtual line

# is occupied by the programm xdm.

# This is for the package xdmsc, after installing and

# and configuration you should remove the comment character

# from the following line: #7:3:respawn:+/etc/init.d/rx tty7

# modem getty.

# mo:235:respawn:/usr/sbin/mgetty -s 38400 modem

# fax getty (hylafax)

# mo:35:respawn:/usr/lib/fax/faxgetty /dev/modem

# vbox (voice box) getty

# I6:35:respawn:/usr/sbin/vboxgetty -d /dev/ttyI6

# I7:35:respawn:/usr/sbin/vboxgetty -d /dev/ttyI7

# end of /etc/inittab

As you can see, many tasks take place in /etc/inittab. The first task that really matters is the definition of the default runlevel for your server. The runlevel is the default status in which your server is started; it determines the number of services that start when booting the server. By default, SUSE Linux Enterprise Server uses runlevel 5. In this runlevel you have a fully functional server, including a graphical user interface that starts by default. Because most system administrators consider this graphical user interface unnecessary, many prefer runlevel 3 as the default. This runlevel starts the same number of services but doesn't start the graphical user interface by default. After all, if you do really need a graphical user interface, you can just use the startx command from the console.

When setting the default runlevel to something else, you should be careful. Runlevels 3 and 5 do fine, but other runlevels usually are not a good choice as the system default. Imagine, for example, what would happen if you set the default runlevel to runlevel 6, which is the runlevel that reboots your server!

After the definition of the default runlevel, the boot script is called from the line si:: bootwait:/etc/init.d/boot. This line calls the first boot script, which is covered in the next section. After that, the runlevels are defined, and the rc script is called. This script then activates all the services that need to be started in the runlevels. You'll learn much more about this in the later section "Managing Services Start-Up."

After the definition and calling of the runlevels, you'll see the following lines:

ls:S:wait:/etc/init.d/rc S :S:respawn:/sbin/sulogin

These two lines define what should happen when entering single-user mode (let's call this the Linux safe mode). In this mode, the sulogin command is called. This command asks for the password of the user root. This ensures that also in single-user mode, a password has to be entered before the root prompt opens.

Caution The sulogin program may give you a false sense of protection. When someone enters init=/ bin/bash at the boot prompt of your server, he will get a root prompt without entering the root user's password. Therefore, be sure to physically secure your server to prevent a compromise of this nature.

You may have noted that all the lines in /etc/inittab follow more or less the same structure. All the lines consist of four fields, and these four fields make sure that some command is executed. In the first field, a unique identifier is used. It doesn't really matter what you use here, as long as it is unique. Next, in the second field the runlevels where this line has to be active are defined. This field may be empty, in which case the line is used in all runlevels. Next, the third field contains a definition of the way that the command that is executed should be executed. You can use different options in this field:

respawn: The process is restarted whenever it is terminated.

wait: The process starts once when the specific runlevel is entered, and init will wait for its termination.

once: The process runs only once.

boot: The process will be executed during system boot. If this option is used, the runlevels field is ignored.

bootwait: The process is executed during system boot, and init waits for its execution before continuing.

off: The process is disabled.

ondemand: This is a rarely used option that can be used when a nondefault "on-demand" runlevel is called.

initdefault: This specific option specifies the default runlevel that should be started when booting the system.

sysinit: The process is executed during system boot, even before the lines with the boot option are executed.

powerwait: This command is executed when the power goes down. To let this work, some process must be running that talks to the UPS. init waits for the execution of this process to complete.

powerfail: Like powerwait, but init does not wait for the process to complete.

powerfailnow: This process is executed when init is told that the battery of the UPS is almost empty.

resume: This command is executed when software suspend has resumed on this machine.

ctrlaltdel: This command is executed when the Ctrl+Alt+Del key sequence has been used.

kbrequest: Use this option to activate a command when a signal is received by a special key combination from the keyboard.

Back to the important lines in /etc/inittab: the next important line after calling sulogin in single-user mode is the line where the Ctrl+Alt+Del key sequence is captured. Usually, this key sequence will have a system reboot as its result; the reboot is initiated by the shutdown command. This is all defined in the following line of code:

ca::ctrlaltdel:/sbin/shutdown -r -t 4 now

Some administrators like this feature; after all, it does help you reboot the system gracefully when problems occur. On the other hand, it may cause you some problems when someone uses the Ctrl+Alt+Del sequence by accident. Therefore, it is good to know that you can define something else to happen when Ctrl+Alt+Del is pressed. Just replace the /sbin/shutdown command with something more useful, such as with /bin/logger "someone pressed Ctrl+Alt+Del." That way, only a message is written to the log file, and nothing really happens.

Note Make sure always to use the complete command, including its path when calling a command from /etc/inittab. This is because from inittab, no search path is available yet.

The next important block of lines in /etc/inittab are the lines where the powerfail process is called. This process is called when a problem occurs with the power on your server. The only step you as an administrator need to take is to make sure the powerfail process starts. These lines will do the rest. The lines that do this are repeated in the following listing:

# what to do when power fails/returns pf::powerwait:/etc/init.d/powerfail start pn::powerfailnow:/etc/init.d/powerfail now #pn::powerfail:/etc/init.d/powerfail now po::powerokwait:/etc/init.d/powerfail stop

# for ARGO UPS

sh:12345:powerfail:/sbin/shutdown -h now THE POWER IS FAILING

The last important piece of code in /etc/inittab are the lines where the mingetty process is called:

1:2345:respawn:/sbin/mingetty --noclear tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6

The mingetty process is the process that creates virtual consoles on your server. It opens the virtual console and displays a login prompt on it. As the argument for mingetty, the name of the virtual console is mentioned. As you can see, by default virtual consoles are started for tty1 until tty6. From these lines, it is relatively easy to create an additional virtual console on, for example, tty8; just add the following line:

8:2345:respawn:/sbin/mingetty tty8

Caution When defining new virtual consoles, make sure you are not redefining a tty that is already in use. For example, tty7 is already used by your graphical environment, and tty10 is already used for logging purposes. Don't redefine them!

Be aware that all changes to /etc/inittab have to be activated. This is because the init process usually reads only its inittab when booting your server. To activate manual changes you have made to /etc/inittab, use the init q command.

At the end of /etc/inittab, some more lines are included, but they are all commented out. You can activate these lines when you need to make a serial connection directly to your server or when you want to use your server for dialing with a modem. Since these techniques are not used often anymore, I won't cover them in this book.

+1 0

Post a comment