Linux Mastery
The Human Knowledge Project
Chapter 16 — Services, Boot & systemd
Why This Chapter Matters
Modern Linux systems perform an enormous amount of work automatically behind the scenes.
When Linux starts, it must:
- initialize hardware
- detect storage devices
- start networking
- launch logging services
- prepare printers
- initialize audio
- start graphical environments
- provide a login screen
All of these tasks occur before you begin using the computer.
On most modern Linux distributions, they are coordinated by a system called systemd.
Understanding services, daemons, the Linux boot process, and systemd is essential for Linux administration and troubleshooting.
Learning Objectives
Upon completing this chapter, you will be able to:
- describe the Linux boot process
- explain the purpose of systemd
- distinguish between services, daemons, and processes
- view running services
- understand system startup targets
- explain why system logs are important
- understand how Linux manages background services
Introduction
When you press the power button, your computer does far more than simply "start Linux."
Hundreds of individual tasks occur in a carefully organized sequence.
Hardware is initialized.
The operating system loads.
Background services begin running.
Networking becomes available.
Finally, the login screen appears.
Most users never see these steps, yet every Linux system depends on them.
Understanding this startup process makes troubleshooting much easier and provides a deeper understanding of how Linux works.
1. What Happens During Boot?
Starting a Linux system is called booting.
During boot, Linux progresses through several stages before presenting a login prompt.
A simplified boot sequence looks like this:
BIOS / UEFI
↓
Bootloader
↓
Linux Kernel
↓
systemd
↓
Services
↓
Login
THKI Memory Aid
Power On ↓ BIOS / UEFI ↓ Bootloader ↓ Linux Kernel ↓ systemd ↓ Services ↓ Login
Each stage prepares the next until the operating system is fully operational.
2. The Role of systemd
On most modern Linux distributions, the initialization system is:
systemd
Once the Linux kernel finishes loading, it starts systemd.
From that point forward, systemd becomes responsible for bringing the operating system into a usable state.
It manages:
- system startup
- background services
- logging
- device management
- timers
- system targets
Because so many parts of Linux depend upon it, systemd is one of the most important components of a modern Linux system.
THKI Insight
Most Linux users interact with
systemdevery day without realizing it.Every time your computer starts,
systemdquietly launches the services that make the operating system usable.
3. Why systemd Exists
Earlier Linux systems used initialization systems such as:
- SysVinit
- Upstart
As Linux grew more sophisticated, operating systems required:
- faster startup
- dependency management
- parallel service startup
- centralized logging
- unified administration
systemd was designed to address these needs by providing one consistent framework for managing the entire startup process.
4. What Is a Service?
A service is a program that runs in the background to provide functionality for the operating system.
Examples include:
- networking
- SSH servers
- printing
- web servers
- audio systems
- graphical login managers
Many services begin automatically during the boot process and continue running until the computer shuts down.
Without these services, much of Linux would simply not function.
5. What Is a Daemon?
A daemon is a background program that operates without direct user interaction.
Examples include:
sshdcupsdsystemd-journald
In everyday Linux usage, the terms daemon and service are often used interchangeably.
A daemon performs work quietly in the background while users interact with the system normally.
6. Why Daemons Matter
Daemons allow Linux to perform continuous work even when no user is actively interacting with the computer.
Examples include:
- serving web pages
- monitoring hardware
- collecting log information
- managing printers
- maintaining network connections
Without daemons, Linux would require constant user intervention to perform routine system tasks.
7. Viewing Running Services
To display active services:
systemctl list-units --type=service
This command displays services currently managed by systemd.
Depending on your system, the list may contain hundreds of entries.
Viewing this list gives you an appreciation for how much work Linux performs automatically behind the scenes.
8. systemctl — Controlling Services
The primary command used to manage services under systemd is:
systemctl
It allows administrators to:
- start services
- stop services
- restart services
- reload services
- enable automatic startup
- disable automatic startup
- inspect service status
Learning systemctl is one of the most important Linux administration skills.
9. Viewing Service Status
To display information about a service:
systemctl status ssh
Typical information includes:
- whether the service is running
- process ID (PID)
- startup status
- recent log messages
This is often the first command administrators use when troubleshooting a service.
10. Starting, Stopping, and Restarting Services
To start a service immediately:
sudo systemctl start ssh
To stop a running service:
sudo systemctl stop ssh
To restart a service:
sudo systemctl restart ssh
Some services can reload their configuration without fully restarting.
Example:
sudo systemctl reload ssh
Reloading is often faster and avoids interrupting active users.
11. Starting Services Automatically
Some services should begin every time Linux boots.
Enable automatic startup:
sudo systemctl enable ssh
Disable automatic startup:
sudo systemctl disable ssh
Enabling a service does not necessarily start it immediately.
It simply tells Linux to start the service automatically during future boots.
THKI Memory Aid
start ↓ Run Now stop ↓ Stop Now restart ↓ Stop + Start enable ↓ Start at Boot disable ↓ Do Not Start at Boot
Remember:
- start affects the current session.
- enable affects future boots.
12. Checking Service Status
To determine whether a service is currently running:
systemctl is-active ssh
To determine whether it is configured to start automatically during boot:
systemctl is-enabled ssh
These commands provide quick answers without displaying the detailed output of systemctl status.
13. Unit Files
systemd manages many different types of resources called units.
Common unit types include:
| Unit Type | Purpose |
|-----------|---------|
| service | Background services |
| target | Operating states |
| mount | Mounted filesystems |
| timer | Scheduled tasks |
Most administrators work primarily with service units.
14. Unit File Locations
Service definitions are stored in unit files.
Common locations include:
/etc/systemd/system/
and:
/usr/lib/systemd/system/
To examine a unit file:
less /usr/lib/systemd/system/ssh.service
These files describe how services start, stop, and interact with other system components.
15. Boot Targets
systemd uses targets to represent different operating states.
Targets replace the older Linux concept of runlevels.
Common targets include:
| Target | Purpose |
|---------|---------|
| graphical.target | Graphical desktop |
| multi-user.target | Multi-user text mode |
| rescue.target | Repair and recovery |
| reboot.target | Restart the system |
Targets determine which services Linux starts during boot.
16. Viewing and Changing the Default Target
To display the default startup target:
systemctl get-default
To change it:
sudo systemctl set-default multi-user.target
Changing the default target changes how Linux starts the next time the computer boots.
17. Graphical and Text Modes
A graphical target starts:
- the display manager
- the desktop environment
- a graphical login screen
A multi-user target normally starts:
- networking
- system services
- text-based logins
without launching a desktop environment.
Servers commonly use the multi-user target because they do not require a graphical interface.
18. Rescue Mode
Sometimes Linux must start with only minimal services.
This special operating state is called:
rescue mode
Rescue mode is useful for:
- repairing damaged filesystems
- resetting passwords
- recovering from configuration errors
- troubleshooting startup problems
Because only essential services are loaded, rescue mode provides a controlled environment for system repair.
19. journalctl — Viewing System Logs
Modern Linux systems use a centralized logging system called the system journal.
The primary command for viewing these logs is:
journalctl
The system journal records information from:
- the Linux kernel
- system services
- device drivers
- applications
- the boot process
Because so much information is recorded, the journal is one of the first places administrators look when troubleshooting problems.
THKI Insight
Experienced Linux administrators rarely guess why something failed.
They consult the system logs first.
20. Viewing Journal Entries
Display the entire system journal:
journalctl
Large systems may contain thousands of log entries.
To display only the most recent entries:
journalctl -n 50
This displays the last 50 log messages.
To follow new log entries as they occur:
journalctl -f
This behaves much like:
tail -f
and is useful when monitoring a system in real time.
21. Viewing Logs for Individual Services
To display log messages for a specific service:
journalctl -u ssh
To display only messages from the current boot:
journalctl -b
Filtering logs in this way makes troubleshooting much faster than searching through the entire system journal.
22. Why Logs Matter
System logs help administrators diagnose:
- failed boots
- hardware problems
- service failures
- network issues
- application crashes
- security events
Nearly every Linux troubleshooting session eventually involves reading log files.
23. Analyzing Boot Performance
systemd can measure how long the system takes to boot.
Display overall boot timing:
systemd-analyze
Display the slowest startup services:
systemd-analyze blame
These commands help identify services that delay system startup.
Administrators often use them when optimizing boot performance.
24. Failed Services
To display services that failed to start:
systemctl --failed
This command quickly identifies problems that might otherwise be difficult to locate.
It is one of the first commands many administrators run after an unsuccessful boot or service failure.
25. Rebooting and Shutting Down
Restart the system:
sudo reboot
Shut the system down immediately:
sudo shutdown now
Schedule a shutdown in ten minutes:
sudo shutdown +10
These commands allow administrators to manage system power safely and predictably.
26. Why systemd Is Sometimes Controversial
Although systemd is used by most modern Linux distributions, it has also generated discussion within the Linux community.
Supporters appreciate:
- faster startup
- centralized management
- dependency handling
- integrated logging
Critics argue that it:
- is more complex than earlier systems
- performs too many different functions
- moves away from traditional UNIX design philosophy
Regardless of these opinions, understanding systemd is an essential Linux administration skill.
27. Real-World Administrative Workflow
A Linux administrator might routinely:
- inspect failed services
- restart networking
- review system logs
- enable or disable startup services
- analyze boot performance
- troubleshoot daemon failures
A typical workflow might look like this:
Check for failed services:
systemctl --failed
Review recent log messages:
journalctl -xe
Restart the affected service:
sudo systemctl restart service_name
This systematic approach is far more effective than simply guessing at the cause of a problem.
28. Safety Note
Services are part of the operating system's infrastructure.
Changing startup targets or disabling important services can:
- prevent networking
- disable graphical login
- interrupt printing
- affect security
- prevent successful booting
Before changing critical services, understand what they do and why they are running.
Chapter Summary
| Command / Concept | Purpose |
|-------------------|---------|
| systemd | Initialization and service manager |
| systemctl | Manage services and system targets |
| Service | Background program providing system functionality |
| Daemon | Background process |
| journalctl | View the system journal |
| Target | Operating state managed by systemd |
| systemd-analyze | Analyze boot performance |
Key Ideas
Modern Linux systems depend heavily on background services.
Understanding:
- the boot process
systemd- services
- daemons
- targets
- system logs
provides the foundation for effective Linux troubleshooting and administration.
Many Linux problems can be solved by examining service status and reading the system logs.
Practice Exercises
- Display all running services.
- Check the status of a service.
- Start and stop a service (if permitted).
- Restart a service.
- Enable a service at boot.
- Disable a service.
- Determine whether a service is active.
- Determine whether a service is enabled.
- Display the default boot target.
- Compare
graphical.targetandmulti-user.target. - View the system journal.
- Display the last 50 journal entries.
- Follow the journal in real time.
- Display logs from the current boot.
- Display logs for a specific service.
- List failed services.
- Analyze boot performance.
- Display the slowest startup services.
- Explain the difference between a service, a daemon, and a process.
- Describe a troubleshooting workflow using:
systemctljournalctlsystemd-analyze
- Explain why Linux depends on background services.
- Describe the purpose of rescue mode.
- Explain why system logs are essential for troubleshooting.
- Describe a real-world problem caused by a failed service.
Looking Ahead
You now understand how Linux starts, manages services, and records system activity.
In the next chapter, you will learn how Linux schedules work to occur automatically using jobs, timers, and task scheduling—allowing the operating system to perform routine work even when no one is logged in.