Using basic systemd commands
Control Plan
Systemd is a complex management structure with many commands and capabilities. We provide an overview of a few basic commands and their use.
One of the criticisms of systemd, the new system management framework [1], is that it is a monolithic structure that violates the time-honored Unix principle of using small, dedicated tools. However, when you examine it, systemd proves less monolithic than it sounds. Instead, it has introduced a series of new tools for system administration, each of which has its own specific purpose.
What gives systemd a monolithic appearance is that its structure is consistent throughout. Users can be confident that a file ending in "ctl" is a command, whereas one ending in "conf" is a configuration file. Even more importantly, each command has the same structure:
COMMAND SUB-COMMAND OPTIONS
Often, options and sub-commands are the same for different commands.
Systemd tends to thoroughness, so it is impractical to list all of the main options and commands here. Instead, there is room only for some basic functions to give a sense of what each command can do. For more detailed information, consult each command's man page or the systemd documentation [2]. You can get a sense of the complexity of systemd from the fact that systemctl
, the most important systemd command, has a man page of 868 lines – more than four times as long as a command such as cp
or ls
. In this article, I'll describe some of the basic commands introduced by systemd.
Systemctl
Systemctl is systemd's main command. It manages units, which are the files to manage system resources. Units are organized into control groups, such as service, socket, device, mount, automount, and snapshot, which stores an image of the current state of systemd for later restoration. These control groups are used as an extension for unit files, so you always know which control group a unit belongs to. A system can have between 150 and 300 units, depending on its setup and what it runs. Usually, systems that run Gnome technologies have more units than KDE, possibly because systemd was initially developed with Gnome in mind.
The systemctl
command manages units – enabling and disabling them, changing their state, and managing positive dependencies (what must be present for a unit to operate) and reverse dependencies (what cannot be present for a unit to operate). This broad array of controls makes systemctl
extremely powerful – and, therefore, potentially capable of crashing your machine if used carelessly.
You can use --all
(-a
) to see a list of units as you compose the command structure (Figure 1). To avoid unintended consequences, whenever possible, add the option --type=
(-t
), to limit the command to particular control groups such as sockets or service, --state=
, to specify whether units whose state is LOAD, SUB, or ACTIVE are affected, or both options. Use the command list-dependencies
to view a unit's dependencies, and the --reverse
option to list a unit's reverse dependencies.
Most of systemctl's basic functions are in its commands. With show
and status
, you can read current information about a unit or a comma-separated list of units. The start
and stop
commands activate a unit, whereas
set-property UNIT-NAME PARAMETER SETTING
edits a unit's definition.
Journalctl
Journals are one the more controversial features of systemd, because they are binary files rather than the traditional text files generally used in Linux. However, in compensation, the journalctl
command has a thorough selection of choices for viewing logs.
Many distributions do not ship with systemd's journal enabled, so check to see if your installation has a /var/log/journal
file. If not, you can set it up with the command:
setfacl -R -nm g:adm:rx,d:g:adm:rx /var/log/journal
You should also edit /etc/systemd/journald.conf
, using the settings storage=persistent
to save the journal permanently and SystemMaxFileSize = 100M
so that the journal does not grow too large.
The bare command displays the journal, oldest entry first (Figure 2). However, for convenience, consider adding the option --output=verbose
so that information is not cut off and --reverse
(-r
) so that the oldest entry is first.
You can filter journal messages with --dmesg
(-k
) to view only messages from the kernel, with --system
for messages from system services, or with --PID=
to view messages from a particular service. If you want to view messages from a particular book, run journalctl
with --system-boots
, then use the identifier in the second field of the output to run the records for the boot you want to examine. Alternatively, you can use line=NUMBER
to view only a set number of events or use --since
or --until
to set a range of dates or times.
Halt, Poweroff, Reboot, Shutdown
These commands all close down the system. Technically, halt
closes down the system without turning the power off, whereas poweroff
and shutdown
do turn the power off, and reboot
does a cold reboot. However, all four commands include the options --poweroff
and --reboot
, so any distinction is blurred.
The shutdown
command is unique in that options may be followed by a time to activate the command. The time is in hh:mm format, using a 24-hour clock. You also have the option of specifying a time in the future by specifying a number of minutes with a plus sign as a prefix. If no time is specified, then the default is +1
. Using +0
runs the command immediately. At the end of a shutdown command with a time argument, you can use the wall
command to broadcast a message to all users.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.