SysVinit
SysVinit, also known as System V init or simply "init," is one of the oldest and most traditional init systems used in Unix and early Linux distributions. It is responsible for initializing the system, starting and stopping services, and changing runlevels.
Overview of SysVinit
Key Concepts
Initialization Scripts: Located in
/etc/init.d/
, these scripts are used to start, stop, and manage services.Runlevels: Define different states of the system, each of which is associated with a specific set of services and processes.
Inittab File: The main configuration file (
/etc/inittab
) that defines how the system should be initialized and which services should be started at each runlevel.
Runlevels
0: Halt the system
1: Single-user mode (maintenance or emergency mode)
2: Multi-user mode without networking
3: Multi-user mode with networking
4: Unused (can be user-defined)
5: Multi-user mode with networking and graphical interface
6: Reboot the system
Initialization Process
Kernel Boot: The kernel is loaded into memory by the bootloader and begins initialization.
Run Init: The kernel starts the
init
process, which reads the/etc/inittab
file.Set Runlevel: The
init
process sets the default runlevel specified in the/etc/inittab
file.Execute Scripts: The
init
process executes the appropriate scripts for the current runlevel, starting and stopping services as needed.
/etc/inittab
Configuration
/etc/inittab
ConfigurationThe /etc/inittab
file contains configuration directives for the init
process. Each line in the file defines an action to be taken when the system enters a particular runlevel.
Example /etc/inittab
/etc/inittab
Service Management
Services in SysVinit are managed using scripts located in /etc/init.d/
. These scripts accept commands such as start
, stop
, restart
, and status
.
Example: Managing a Service
Starting a Service:
Stopping a Service:
Restarting a Service:
Checking Status of a Service:
Runlevel Directories
Runlevel directories (/etc/rc.d/
or /etc/rc?.d/
) contain symbolic links to the initialization scripts in /etc/init.d/
. These directories are named according to their corresponding runlevel (e.g., rc0.d
, rc1.d
, etc.).
Example: Runlevel 3 Directory (/etc/rc3.d/
)
/etc/rc3.d/
)K: Stands for "kill" and is used to stop services.
S: Stands for "start" and is used to start services.
The numbers following K
and S
determine the order in which services are started or stopped.
Conclusion
SysVinit is a foundational init system that uses scripts and runlevels to manage the initialization and shutdown of services on Unix and early Linux systems. Understanding how to configure and manage SysVinit is crucial for maintaining and troubleshooting systems that use this traditional init system.
Last updated