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
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.