When System V-style init programs are started by the kernel, they read their configuration file, /etc/inittab. This file defines:
- the runlevel in which init will start the system by default
- programs init will run to initialize the system
- standard processes init will start for each runlevel
- scripts init will run to implement each runlevel
By default, most servers are started in runlevel 3, while most workstations are started in runlevel 5. This default can be overridden at boot time by configuring the bootloader to pass init an option specifying an alternate runlevel.
/etc/inittab Line Syntax
A line in the /etc/inittab file has four fields that are colon delimited.
– The first is a unique ID. It doesn’t matter what the value is as long as no other line has the same 1 or 2 characters.
– The second is the list of runlevels to restrict this line to. If none are listed, the line will be processed regardless of the default runlevel.
– The third field is the action that will be taken (usually executing the command specified in the fourth field).
The following table describes the fields in an inittab entry.
|id||Is a unique identifier for the entry.|
|rstate||Lists the run levels to which this entry applies.|
|action||Identifies how the process that is specified in the process field is to be run. Possible values include: sysinit, boot, bootwait, wait, and respawn. For a description of the other action keywords, see inittab(4).|
|process||Defines the command or script to execute.|
The initdefault line in /etc/inittab tells init which runlevel to go to if it has not been given that information. This line is special in that there is no command to run (all others have a value in the fourth fiedl):
Sample /etc/inittab file
Below is a sample /etc/inittab file from CentOS 6 system.
# cat /etc/inittab # inittab is only used by upstart for the default runlevel. # # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # System initialization is started by /etc/init/rcS.conf # # Individual runlevels are started by /etc/init/rc.conf # # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf # # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf, # with configuration in /etc/sysconfig/init. # # For information on how to write upstart event handlers, or how # upstart works, see init(5), init(8), and initctl(8). # # Default runlevel. The runlevels used 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) # id:3:initdefault:
/etc/rc.d/rc.sysinit Boot Script
The /etc/rc.d/rc.sysinit script is called by the init program on boot. This script performs initial setup that is run-level agnostic. The following are examples of things done by the rc.sysinit script:
- peripheral hardware such as USB, parallel or serial connected devices are configured
- kernel parameters which are specified in /etc/sysctl.conf get applied to the running kernel
- Sets the hostname
- the root filesystem is checked and remounted read/write
- RAID and LVM devices are activated
- Swap files and partitions are activated
- disk quotas activated