Init systems are the first processes started by the Linux kernel during boot. They manage system initialization, service startup/shutdown, and process supervision throughout the system’s lifecycle. Modern Linux distributions primarily use systemd, though alternatives like SysV init and OpenRC exist.
Key Concepts
- PID 1: The init system always runs as process ID 1
- Service Management: Starting, stopping, and monitoring services
- Dependency Management: Handling service dependencies and boot order
- Target/Runlevel: Different system states (multi-user, graphical, rescue)
- Unit Files: Configuration files defining services and their behavior
- Socket Activation: Starting services on-demand when needed
Command Syntax
systemd (most common)
systemctl [command] [unit-name]
- Primary tool for managing systemd services
- Controls service states and system targets
SysV Init (legacy)
service [service-name] [action]
- Traditional service management command
- Still available on many systems for compatibility
Common Options
systemd commands
start - Start a service
stop - Stop a service
restart - Restart a service
reload - Reload service configuration
enable - Enable service at boot
disable - Disable service at boot
status - Show service status
list-units - List all units
Practical Examples
Example 1: Check systemd status
|
|
Shows overall system state and recent log entries
Example 2: Manage a service
|
|
Basic service lifecycle management
Example 3: View all services
|
|
Lists all loaded service units and their states
Example 4: Change system target
|
|
Changes the current system state
Example 5: View service logs
|
|
Examine service-specific log entries
Use Cases
- System Boot: Starting essential services during startup
- Service Management: Daily administration of system services
- Troubleshooting: Diagnosing boot issues and service failures
- Automation: Scripting service management tasks
- Resource Management: Controlling service resource usage
- Security: Managing service permissions and isolation
Related Commands
journalctl - View systemd logs
systemd-analyze - Analyze boot performance
loginctl - Manage user sessions
hostnamectl - Control system hostname
timedatectl - Manage system time/date
localectl - Configure system locale
Tips & Troubleshooting
Common Issues
- Service won’t start: Check
systemctl status service-nameandjournalctl -u service-name - Boot hangs: Use
systemd-analyze critical-chainto find bottlenecks - Service conflicts: Review unit file dependencies
Performance Tips
- Use
systemd-analyze blameto identify slow-starting services - Disable unnecessary services with
systemctl disable service-name - Consider socket activation for rarely-used services
Security Notes
- Services run with minimal privileges by default in systemd
- Use
systemctl edit service-nameto safely modify service configs - Regular audit of enabled services recommended
Legacy System Notes
- On SysV systems, check
/etc/init.d/for service scripts - Runlevels 0-6 correspond to different system states
- Use
chkconfigorupdate-rc.dfor SysV service management