Yahoo
Advertisement
Advertisement
Advertisement
Advertisement

4 systemd tools that make everyday Linux troubleshooting much easier

systemd logo and the Linux mascot using a laptop in front.
Lucas Gouveia/How-To Geek

Some people love systemd and can't stop raving about it; others love to hate it and can't stop throwing shade at it. Even though systemd remains divisive , one thing's for sure: since nearly all modern Linux distributions have adopted it as their default init system, learning to use it can pay off big time. Here's a basic overview of how to use four systemd tools that make troubleshooting on Linux a breeze.

Systemctl: The modern way to manage services

Systemctl is the gateway to service management on systemd-based Linux distributions . It can start and stop services, restart or reload them, enable or disable them, and help you learn so much more about the status of the different services on your system. Checking the status of a particular service is usually the first step in troubleshooting. You can use systemctl to show all running service units:

Using systemctl to list all active service units

The state option can tell you more about failed services:

Using systemctl to list all failed service units

You can also list active and inactive service units:

Using systemctl to list active and inactive units

Want to check the status of a specific service, such as a custom wallpaper changer? Ask systemctl for a status update. You can also check if a service will auto-start whenever you boot and reboot, and if it's not enabled, you can easily enable it:

Using systemctl to show the status of a custom wallpaper service unit
Advertisement
Advertisement

Starting, stopping, and restarting a service is also a breeze with systemctl. The start option is the easiest way to start a service. If a service is not running at boot time, you can enable it, and if you don't want a service to start at boot time, you can disable it:

A screenshot showing how to use systemctl to enable services to start at boot time

For help, use:

Journalctl: Making sense of service logs

Systemctl is a quick way to manage and troubleshoot services. But if you're looking for more information about a service, journalctl is the tool for the job. Journalctl is easy to use ; it lets you dive deeper into a service's log, which is usually a treasure trove of information.

The primary way I use it is to filter the log file output for a specific service. For example, I can use it to show only the log file of the custom wallpaper changer I automated with a systemd timer .

Journalctl -u python3 -u wallpaper-changer

You can use it to show multiple log files of specific service units, depending on the service you're troubleshooting. For narrower results, use date and time filters to limit the log file output, which is usually a good way to determine when a service error occurred or when it started. For example, you can use the 'since' option to show logs using relative and exact time:

Using journalctl to show time-based service logs

You can also show the log file of the current and previous boot sessions:

journalctl to show current boot log files
Advertisement
Advertisement

To show a service's log in real-time, use the f option to follow it.

Using journalctl to show a live log file output

To troubleshoot services that have failed to start, use:

Using journalctl xe option

You can also limit the number of lines in a log file or show the log entries from the newest to the oldest:

Using Journalctl to show time-based service logs for wallpaper-changer-1

For help, use:

Systemd-analyze: Discover the services slowing down your computer

Is your Linux system booting slower than a snail on a hot, dry day? If it is, systemd-analyze is the tool for you. You can use it to understand how the various services on your computer impact boot time. That means you can use it to identify services or configuration errors that may be slowing down system startup. The first way to use it is by analyzing the overall boot time:

systemd-analyze basic
Advertisement
Advertisement
  • Kernel: This is the time the system has spent initializing system drivers and hardware.

  • Userspace: This represents the time taken to initialize and start services.

If you suspect that a service is causing your system to boot slowly, but you're not sure which service could be causing it, you can analyze services based on how much time they contribute to the boot time:

A screenshot of systemd-analyze blame command

The basic visualization features in systemd-analyze can print out a simple graphical timeline or chart of the services that start during and after the boot sequence.

Systemd-analyze plot > boot.svg creates an SVG chart of all system services and saves it in your home folder. Drag and drop the SVG in your browser to view it. Services with the longest bars take the longest to load. Troubleshoot those first.

A screenshot sowing a systemd-analyze critical chain command

For help, use:

Coredumpctl: Inspect crash reports

If some services keep crashing randomly or unexpectedly, coredumpctl can help you inspect, troubleshoot, and resolve the issue. However, if you've never used coredumpctl, it may be unavailable on your device. Install it by updating your system and executing sudo apt install systemd-coredump. Once installed, you can use the list option to see a table of all crashed services and processes:

A screeshot of the coredumctl list command

To inspect and troubleshoot a particular crash, use its Process ID:

A screenshot showing how to use coredumpctl to inspect a program usings its PID
Advertisement
Advertisement

If you're troubleshooting a particular program or service, filter for that specific program/service:

Using coredump to filter core dump by name

For help, use:


Systemd has many other tools and features. It can also do so much more. Ultimately, experimenting with these four systemd tools is a small step towards becoming a pro at troubleshooting Linux programs and services.

Advertisement
Advertisement
Mobilize your Website
View Site in Mobile | Classic
Share by: