System Startup, Boot Targets, and Runlevels

Understanding the Linux boot process and system initialization is crucial for system administration, troubleshooting, and optimization. From traditional SysV init to modern systemd, this guide covers the complete startup ecosystem, including boot targets, runlevels, and service management for efficient system control.

Init Systems Comparison: systemd vs SysV init

Aspect systemd SysV init
Architecture Parallel, event-driven Sequential, script-based
Boot Speed Faster (parallel startup) Slower (sequential)
Configuration Unit files (.service, .target) Init scripts in /etc/init.d/
Dependency Management Automatic, declarative Manual, script-based
Logging journald (binary logs) Text files in /var/log/
Status Modern standard Legacy, deprecated
Quick Reference:
systemd - Modern init system (most distributions)
SysV init - Traditional init system (legacy systems)
systemctl - Control systemd and services
journalctl - View system logs
runlevel - Check current runlevel (SysV)
init - Change runlevels (SysV)
• Boot targets replace runlevels in systemd

Linux Boot Process Workflow

Complete System Startup Sequence

BIOS/UEFI
Bootloader
Kernel
Init
Runlevel/Target

Traditional SysV Runlevels

Runlevel Description Purpose Directory
0 Halt System shutdown /etc/rc0.d/
1 Single User Maintenance mode /etc/rc1.d/
2 Multi-user Without networking /etc/rc2.d/
3 Multi-user With networking /etc/rc3.d/
4 User-defined Custom purposes /etc/rc4.d/
5 Graphical With display manager /etc/rc5.d/
6 Reboot System restart /etc/rc6.d/

systemd Boot Targets

Boot Target Equivalent Runlevel Description Purpose
poweroff.target 0 System power off Shutdown system
rescue.target 1 Rescue mode Single user maintenance
multi-user.target 3 Multi-user console Text mode with networking
graphical.target 5 Graphical interface Full desktop environment
reboot.target 6 System reboot Restart system

Essential systemd Commands

⚙️
systemctl

Control the systemd system and service manager.

systemctl [options] command [unit...]

Service Management:

  • systemctl start service - Start service
  • systemctl stop service - Stop service
  • systemctl restart service - Restart service
  • systemctl reload service - Reload configuration
  • systemctl status service - Check status

Enable/Disable:

  • systemctl enable service - Start at boot
  • systemctl disable service - Don't start at boot
  • systemctl is-enabled service - Check enabled
📊
journalctl

Query and display messages from the journal.

journalctl [options]

Common Usage:

  • journalctl -u service - Service logs
  • journalctl -f - Follow logs
  • journalctl --since "1 hour ago"
  • journalctl -p err - Error messages only
  • journalctl -b - Current boot logs

Filtering:

  • --since and --until for time
  • -p for priority level
  • -u for specific unit
  • _PID= for process ID
🎯
Boot Target Management

Control system boot targets and default targets.

systemctl [isolate|get-default|set-default] target

Target Operations:

  • systemctl get-default - Current default
  • systemctl set-default target - Set default
  • systemctl isolate target - Switch to target
  • systemctl list-unit-files --type=target

Examples:

# Set graphical as default
sudo systemctl set-default graphical.target

# Switch to multi-user
sudo systemctl isolate multi-user.target

# Check current target
systemctl get-default

Boot Process Stages

Stage Component Purpose Key Files
1. Firmware BIOS/UEFI Hardware initialization Firmware settings
2. Bootloader GRUB2 Kernel loading /boot/grub/grub.cfg
3. Kernel Linux Kernel System initialization /boot/vmlinuz*
4. Init systemd/init User space startup /sbin/init
5. Runlevel/Target Services Service management Unit files, init scripts

Traditional Init System Commands

🔄
init

Change system runlevel (SysV init).

init runlevel | telinit runlevel

Common Runlevels:

  • init 0 - Shutdown
  • init 1 - Single user
  • init 3 - Multi-user text
  • init 5 - Graphical
  • init 6 - Reboot

Usage:

# Switch to runlevel 3
sudo init 3

# Check current runlevel
runlevel
N 3
📝
service

Run a System V init script (SysV init).

service SCRIPT COMMAND

Common Commands:

  • service ssh start
  • service ssh stop
  • service ssh restart
  • service ssh status

Init Script Locations:

  • /etc/init.d/ - Main directory
  • /etc/rc*.d/ - Runlevel links
🔗

chkconfig

Update and query runlevel information (SysV init).

chkconfig [--list] [--level levels] service

Common Usage:

  • chkconfig --list - List all services
  • chkconfig --level 35 ssh on
  • chkconfig ssh off - Disable service

Alternative:

  • update-rc.d - Debian alternative

Practical System Management Examples

Real-World System Startup Scenarios

# 1. systemd Service Management
# Check service status
systemctl status ssh
systemctl status nginx
systemctl status mysql

# Start/stop services
sudo systemctl start apache2
sudo systemctl stop mysql
sudo systemctl restart nginx

# Enable/disable services at boot
sudo systemctl enable ssh
sudo systemctl disable telnet
sudo systemctl is-enabled apache2

# 2. Boot Target Management
# Check current default target
systemctl get-default

# Set multi-user as default
sudo systemctl set-default multi-user.target

# Switch to graphical target temporarily
sudo systemctl isolate graphical.target

# List all available targets
systemctl list-unit-files --type=target

# 3. Journal Management
# View system logs
journalctl
journalctl -f  # Follow logs

# View service-specific logs
journalctl -u nginx
journalctl -u ssh --since "1 hour ago"

# View error messages
journalctl -p err -b
journalctl --since "2025-12-03 09:00:00" --until "2025-12-03 10:00:00"

# 4. System Boot Analysis
# View boot time performance
systemd-analyze
systemd-analyze blame
systemd-analyze critical-chain

# Plot boot process
systemd-analyze plot > boot.svg

# 5. Emergency and Rescue Modes
# Boot into rescue mode (systemd)
sudo systemctl rescue

# Boot into emergency mode
sudo systemctl emergency

# From GRUB, add to kernel line:
# systemd.unit=rescue.target
# systemd.unit=emergency.target

# 6. Traditional Init Commands
# Check current runlevel
runlevel

# Change runlevel
sudo init 3
sudo telinit 5

# Manage services (SysV)
sudo service networking restart
sudo service apache2 status

# Configure service startup
sudo chkconfig --list
sudo chkconfig --level 35 httpd on
sudo update-rc.d apache2 enable

# 7. Custom Service Creation
# Create a simple systemd service
sudo nano /etc/systemd/system/myservice.service

# Example service file:
[Unit]
Description=My Custom Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/myscript.sh
Restart=on-failure
User=myuser

[Install]
WantedBy=multi-user.target

# Reload and enable
sudo systemctl daemon-reload
sudo systemctl enable myservice
sudo systemctl start myservice

# 8. Troubleshooting Boot Issues
# Check failed services
systemctl --failed

# Reset failed state
systemctl reset-failed

# Check service dependencies
systemctl list-dependencies nginx

# View service environment
systemctl show nginx

# 9. Runlevel to Target Mapping
# Traditional to systemd conversion:
# init 0 → systemctl poweroff
# init 1 → systemctl rescue
# init 3 → systemctl isolate multi-user.target
# init 5 → systemctl isolate graphical.target
# init 6 → systemctl reboot

# 10. Advanced systemd Features
# Create a user service
systemctl --user start myapp
systemctl --user enable myapp

# Manage systemd timers
systemctl list-timers
systemctl status daily-backup.timer

# Socket activation
systemctl status sockets-enabled

Common Use Cases

System Administration

  • Server Management: systemctl enable|start|stop nginx
  • Boot Optimization: systemd-analyze blame to find slow services
  • Troubleshooting: journalctl -u service --since "1 hour ago"
  • Service Dependencies: systemctl list-dependencies service

Development & Deployment

  • Custom Services: Create systemd unit files for applications
  • Service Monitoring: Use systemctl status for health checks
  • Log Analysis: journalctl for application debugging
  • Boot Testing: Test services in different targets

Maintenance & Recovery

  • Emergency Access: systemctl rescue for single-user mode
  • Service Recovery: systemctl reset-failed to clear errors
  • Boot Repair: Use GRUB to boot different targets
  • Performance Tuning: Disable unnecessary services at boot

Advanced System Management

🔧

Custom Unit Files

Create and manage custom systemd services.

/etc/systemd/system/service.service

Key Sections:

  • [Unit] - Metadata and dependencies
  • [Service] - Service configuration
  • [Install] - Installation info

Example:

[Unit]
Description=My App
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/myapp
Restart=always

[Install]
WantedBy=multi-user.target
⏱️

systemd Timers

Schedule tasks using systemd instead of cron.

.timer files with .service files

Benefits:

  • Integrated logging with journald
  • Systemd dependency management
  • Better error handling
  • Calendar events and monotonic timing

Example:

# /etc/systemd/system/daily-backup.timer
[Unit]
Description=Daily Backup Timer

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target
🛡️

Security Features

systemd security and resource control.

Service security directives

Security Options:

  • PrivateTmp=true - Private /tmp
  • NoNewPrivileges=true - No privilege escalation
  • ProtectSystem=strict - Filesystem protection
  • ReadWritePaths=/path - Allow write access

Resource Control:

  • MemoryLimit=500M
  • CPUQuota=50%
Important Considerations:
• systemd is not available on all systems - know your init system
• Changing default targets/runlevels affects system behavior
• Emergency and rescue modes require physical/console access
• Custom unit files require proper permissions and reloading
• Journal logs are not persistent by default on some systems
• Service dependencies can cause boot failures if misconfigured
• Always test service changes in non-production first
• Understand the difference between systemctl reload and systemctl restart
Pro Tips:
• Use systemd-analyze to optimize boot times
• Create custom targets for specific use cases
• Use journalctl --vacuum-size= to manage log size
• Enable persistent journaling with Storage=persistent
• Use systemctl mask to completely disable services
• Create drop-in files with systemctl edit service
• Monitor failed services with systemctl --failed
• Use hostnamectl and localectl for system info

Key Takeaways

Mastering system startup processes, boot targets, and runlevels is essential for effective Linux system administration. The transition from traditional SysV init to modern systemd has brought significant improvements in boot speed, service management, and system reliability. Understanding both systems ensures you can work effectively across different Linux distributions and versions. Remember that proper service configuration, dependency management, and logging are crucial for maintaining stable and performant systems. Whether you're managing simple services or complex multi-target environments, these foundational skills enable you to control system behavior from boot to shutdown with precision and confidence.

Next Step: Explore advanced systemd features like socket activation, namespaces, and resource control for building secure, efficient, and scalable services.