↓ Skip to main content

Systemctl Command Deep Dive and Usage Tutorial

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 --version

2. Locate systemd and systemctl binaries
#

whereis systemd
whereis systemctl

3. Verify if systemd is running
#

ps -eaf | grep [s]ystemd

4. Analyze system boot duration
#

systemd-analyze

5. Analyze service startup times
#

systemd-analyze blame

6. Visualize the boot chain
#

systemd-analyze critical-chain

📦 Managing Units with systemctl
#

7. List all available units
#

systemctl list-unit-files

8. List all active units
#

systemctl list-units

9. List all failed units
#

systemctl --failed

10. Check if a service is enabled at boot
#

systemctl is-enabled crond.service

11. Check service status
#

systemctl status firewalld.service

12. 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.service

14. Enable/disable service at boot
#

systemctl enable httpd.service
systemctl disable httpd.service

15. Mask/unmask a service
#

systemctl mask httpd.service
systemctl unmask httpd.service

16. Kill a service process
#

systemctl kill httpd

💾 Managing Mount Points
#

17. List mount units
#

systemctl list-unit-files --type=mount

18. Control mount units
#

systemctl start tmp.mount
systemctl stop tmp.mount
systemctl restart tmp.mount
systemctl reload tmp.mount
systemctl status tmp.mount

19–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=socket

22. 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.socket

23–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.service

26. Set CPU shares for a service
#

systemctl set-property httpd.service CPUShares=2000

27. Display all service parameters
#

systemctl show httpd

28. Display critical chain for a service
#

systemd-analyze critical-chain httpd.service

29. List service dependencies
#

systemctl list-dependencies httpd.service

🧩 Control Groups (cgroups)
#

30. Display cgroup hierarchy
#

systemd-cgls

31. View CPU, memory, and I/O activity
#

systemd-cgtop

⚙️ Managing System Runlevels (Targets)
#

32. Enter rescue mode
#

systemctl rescue

33. Enter emergency mode
#

systemctl emergency

34. Show default target
#

systemctl get-default

35–36. Switch between graphical and multi-user modes
#

systemctl isolate graphical.target
systemctl isolate multi-user.target

37. Change default runlevel
#

systemctl set-default graphical.target
systemctl set-default multi-user.target

38. 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.

Related