In this tutorial, we explore how to use systemctl—the primary command-line tool for interacting with systemd—to manage services, sockets, mount points, and system states on modern Linux systems.
💻 Introduction to systemctl #
systemctl is the central tool used to control the systemd system and service manager.
systemd is a modern initialization system replacing the traditional SysV init process. It provides a unified framework for:
- Service management
- Process supervision
- Logging
- Boot analysis
- Dependency control
Most mainstream Linux distributions—including Ubuntu, Fedora, Debian, Rocky Linux, and Arch Linux—use systemd by default.
🚀 Getting Started with systemd and systemctl #
1. Check systemd version #
systemd --version2. Locate systemd and systemctl binaries #
whereis systemd
whereis systemctl3. Verify if systemd is running #
ps -eaf | grep [s]ystemd4. Analyze system boot duration #
systemd-analyze5. Analyze service startup times #
systemd-analyze blame6. Visualize the boot chain #
systemd-analyze critical-chain📦 Managing Units with systemctl #
7. List all available units #
systemctl list-unit-files8. List all active units #
systemctl list-units9. List all failed units #
systemctl --failed10. Check if a service is enabled at boot #
systemctl is-enabled crond.service11. Check service status #
systemctl status firewalld.service12. List all services #
systemctl list-unit-files --type=service🔧 Start, Stop, Restart, and Reload Services #
13. Manage a service (example: httpd) #
systemctl start httpd.service
systemctl restart httpd.service
systemctl stop httpd.service
systemctl reload httpd.service
systemctl status httpd.service14. Enable/disable service at boot #
systemctl enable httpd.service
systemctl disable httpd.service15. Mask/unmask a service #
systemctl mask httpd.service
systemctl unmask httpd.service16. Kill a service process #
systemctl kill httpd💾 Managing Mount Points #
17. List mount units #
systemctl list-unit-files --type=mount18. Control mount units #
systemctl start tmp.mount
systemctl stop tmp.mount
systemctl restart tmp.mount
systemctl reload tmp.mount
systemctl status tmp.mount19–20. Enable/disable/mask/unmask mount units #
systemctl enable tmp.mount
systemctl disable tmp.mount
systemctl mask tmp.mount
systemctl unmask tmp.mount🔌 Managing Socket Units #
21. List socket units #
systemctl list-unit-files --type=socket22. Control a socket (example: cups.socket) #
systemctl start cups.socket
systemctl restart cups.socket
systemctl stop cups.socket
systemctl reload cups.socket
systemctl status cups.socket23–24. Enable/disable/mask/unmask sockets #
systemctl enable cups.socket
systemctl disable cups.socket
systemctl mask cups.socket
systemctl unmask cups.socket📈 CPU Resource Management #
25. View CPU shares for a service #
systemctl show -p CPUShares httpd.service26. Set CPU shares for a service #
systemctl set-property httpd.service CPUShares=200027. Display all service parameters #
systemctl show httpd28. Display critical chain for a service #
systemd-analyze critical-chain httpd.service29. List service dependencies #
systemctl list-dependencies httpd.service🧩 Control Groups (cgroups) #
30. Display cgroup hierarchy #
systemd-cgls31. View CPU, memory, and I/O activity #
systemd-cgtop⚙️ Managing System Runlevels (Targets) #
32. Enter rescue mode #
systemctl rescue33. Enter emergency mode #
systemctl emergency34. Show default target #
systemctl get-default35–36. Switch between graphical and multi-user modes #
systemctl isolate graphical.target
systemctl isolate multi-user.target37. Change default runlevel #
systemctl set-default graphical.target
systemctl set-default multi-user.target38. System power operations #
systemctl reboot
systemctl halt
systemctl suspend
systemctl hibernate
systemctl hybrid-sleep📝 Summary #
This guide provides a complete, hands-on understanding of systemctl and systemd—covering:
- Unit management
- Boot analysis
- Service troubleshooting
- Resource control
- Runlevel/target operations
- Mount and socket management
Mastering systemctl is essential for anyone working in Linux system administration, DevOps, or SRE roles.