init
The init
system is the first process started by the Linux kernel after it has loaded and initialized. It is responsible for initializing the system, starting essential services, and managing system processes. The init
process is the parent of all other processes on a Linux system, and it runs with a process ID (PID) of 1.
Overview of Init Systems
Types of Init Systems
SysVinit: Traditional init system used in older Unix and Linux distributions.
Systemd: Modern init system that has become the standard for many Linux distributions.
Upstart: Event-based init system developed by Ubuntu, now mostly replaced by systemd.
OpenRC: Dependency-based init system used by Gentoo and Alpine Linux.
SysVinit
Key Features
Scripts-Based: Uses shell scripts to start and stop services.
Runlevels: Defines different states of the system, such as single-user mode, multi-user mode, and reboot.
Initialization Scripts: Located in
/etc/init.d/
and linked to corresponding runlevel directories (/etc/rc.d/
or/etc/rc?.d/
).
Runlevels
0: Halt
1: Single-user mode
2: Multi-user mode without networking
3: Multi-user mode with networking
4: Undefined (user-definable)
5: Multi-user mode with graphical interface
6: Reboot
Example: Managing Services with SysVinit
Starting a Service:
Stopping a Service:
Restarting a Service:
Systemd
Key Features
Unit Files: Uses unit files to define services, sockets, devices, mounts, and other system resources.
Parallel Startup: Capable of starting services in parallel, leading to faster boot times.
Dependency Management: Handles dependencies between services to ensure they start in the correct order.
Journal: Provides a logging system called
journal
for collecting and managing logs.
Common Systemd Commands
Starting a Service:
Stopping a Service:
Restarting a Service:
Enabling a Service (to start at boot):
Disabling a Service:
Checking Status of a Service:
Example Unit File
A typical unit file for a service, located in /etc/systemd/system/
or /lib/systemd/system/
, might look like this:
Upstart
Key Features
Event-Based: Uses events to start and stop services.
Backward Compatibility: Can run SysVinit scripts.
Configuration Files: Uses configuration files in
/etc/init/
.
Example Upstart Script
An example Upstart script, located in /etc/init/
, might look like this:
OpenRC
Key Features
Dependency-Based: Manages service dependencies explicitly.
Shell Script-Based: Uses shell scripts for service management.
Compatibility: Compatible with traditional init systems and scripts.
Example: Managing Services with OpenRC
Starting a Service:
Stopping a Service:
Restarting a Service:
Conclusion
The init system is a crucial component of the Linux boot process, responsible for starting and managing system services and processes. Understanding different init systems (SysVinit, systemd, Upstart, OpenRC) and their respective commands is essential for system administration and troubleshooting.
Last updated