SYSTEMD(1)

๐Ÿ’– NAME ๐Ÿ’–

systemd, init โ€” the systemd system and service manager ๐Ÿซถ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

/usr/lib/systemd/systemd [OPTIONS...]

init [OPTIONS...]

โœจ DESCRIPTION โœจ

Okay bestie, sit down, hydrate, because systemd is the system and service manager for Linux operating systems, and it is genuinely the moment. When it runs as the very first process on boot (as PID 1 ๐Ÿคฉ), it acts as the init system that brings up and maintains all your userspace services. And like, it doesn't just do that for the system โ€” separate instances get started for logged-in users so their services can start too. Everybody gets a systemd. Iconic behavior.

systemd is usually not invoked directly by the user, nope, it's installed as the /sbin/init symlink and started during early boot, like a queen arriving before everyone else. The user manager instances get started automatically through the user@.service(5) service, no manual labor required ๐Ÿ’…

When it's running as a system instance, systemd interprets the configuration file system.conf and the files in the system.conf.d directories. When it's running as a user instance, systemd interprets the configuration file user.conf and the files in the user.conf.d directories. Wanna know more? See systemd-system.conf(5), it's giving documentation. ๐Ÿ“–

systemd also contains native implementations of all the little tasks that have to happen during boot. For example, it sets the hostname, it configures the loopback network device... it literally does everything. It also sets up and mounts various API file systems, such as /sys/, /proc/, and /dev/. Chef's kiss ๐Ÿ˜š๐Ÿ‘Œ

Oh and heads up โ€” systemd will also reset the system clock during early boot if it appears to be set incorrectly. See the "System clock epoch" section below for that one. โฐ

Note that some but not all interfaces provided by systemd are covered by the Interface Portability and Stability Promise[1]. So like, check before you rely on it, bestie.

The D-Bus API of systemd is described in org.freedesktop.systemd1(5) and org.freedesktop.LogControl1(5) ๐Ÿ”Œ

And if you're running systemd in a container or initrd environment? Then you should implement the Container Interface[2] or initrd Interface[3] specifications, respectively. Different vibe, different spec, iykyk.


๐Ÿฆ‹ UNITS ๐Ÿฆ‹

systemd provides a whole dependency system between various entities called "units", and there are 11 different types of them. Units encapsulate all sorts of objects that are relevant for system boot-up and maintenance. The majority of units are configured in unit configuration files โ€” the syntax and basic set of options for those is described in systemd.unit(5) โ€” but some are created automatically from other configuration files, dynamically from system state, or programmatically at runtime. Very versatile, very demure ๐Ÿ’…

Units may be in a number of states, described in the following table. And psst โ€” the various unit types may have a number of additional substates, which get mapped to the generalized unit states described here. Don't @ me.

Table 1. Unit ACTIVE states

  • active โ€” Started, bound, plugged in, ..., depending on the unit type. โœจ
  • inactive โ€” Stopped, unbound, unplugged, ..., depending on the unit type.
  • failed โ€” Similar to inactive, but the unit failed in some way (process returned error code on exit, crashed, an operation timed out, or after too many restarts). ๐Ÿ’€
  • activating โ€” Changing from inactive to active. ๐Ÿš€
  • deactivating โ€” Changing from active to inactive. ๐Ÿ‚
  • maintenance โ€” Unit is inactive and a maintenance operation is in progress. ๐Ÿ”ง
  • reloading โ€” Unit is active and it is reloading its configuration. ๐Ÿ”„
  • refreshing โ€” Unit is active and a new mount is being activated in its namespace. ๐ŸŒฑ

๐ŸŒˆ The unit types, ranked (not really, they're all valid)

The following unit types are available:

  1. Service units, which start and control daemons and the processes they consist of. For details, see systemd.service(5).
  2. Socket units, which encapsulate local IPC or network sockets in the system โ€” super useful for socket-based activation. For details about socket units, see systemd.socket(5); for details on socket-based activation and other forms of activation, see daemon(7).
  3. Target units are useful to group units, or to provide well-known synchronization points during boot-up. See systemd.target(5).
  4. Device units expose kernel devices in systemd and may be used to implement device-based activation. For details, see systemd.device(5).
  5. Mount units control mount points in the file system. For details see systemd.mount(5).
  6. Automount units provide automount capabilities, for on-demand mounting of file systems as well as parallelized boot-up. See systemd.automount(5).
  7. Timer units are useful for triggering activation of other units based on timers. You may find details in systemd.timer(5).
  8. Swap units are very similar to mount units and encapsulate memory swap partitions or files of the operating system. They are described in systemd.swap(5).
  9. Path units may be used to activate other services when file system objects change or are modified. See systemd.path(5).
  10. Slice units may be used to group units which manage system processes (such as service and scope units) in a hierarchical tree for resource management purposes. See systemd.slice(5).
  11. Scope units are similar to service units, but they manage foreign processes instead of starting them as well. See systemd.scope(5).

Units are named as their configuration files. Some units have special semantics โ€” the detailed list is available in systemd.special(7) ๐Ÿ‘‘


๐Ÿ’œ Dependencies, jobs, and the whole situation

systemd knows various kinds of dependencies, including positive and negative requirement dependencies (i.e. Requires= and Conflicts=) as well as ordering dependencies (After= and Before=).

NB: ordering and requirement dependencies are orthogonal. If only a requirement dependency exists between two units (e.g. foo.service requires bar.service), but no ordering dependency (e.g. foo.service after bar.service), and both are requested to start, they will be started in parallel. ๐Ÿƒโ™€๏ธ๐Ÿƒโ™€๏ธ It is a common pattern that both requirement and ordering dependencies are placed between two units. Also note that the majority of dependencies are implicitly created and maintained by systemd โ€” in most cases it should be unnecessary to declare additional dependencies manually, however it is possible to do this.

Application programs and units (via dependencies) may request state changes of units. In systemd, these requests are encapsulated as 'jobs' and maintained in a job queue. Jobs may succeed or can fail, and their execution is ordered based on the ordering dependencies of the units they have been scheduled for. It's giving task manager, but make it systemd.

On boot, systemd activates the target unit default.target, whose job is to activate on-boot services and other on-boot units by pulling them in via dependencies. Usually, the unit name is just an alias (symlink) for either:

  • graphical.target โ€” for fully-featured boots into the UI ๐Ÿ–ฅ๏ธ
  • multi-user.target โ€” for limited console-only boots, for use in embedded or server environments, or similar; it's a subset of graphical.target ๐Ÿ–ค

However! It is at the discretion of the administrator to configure it as an alias to any other target unit. Your system, your rules. See systemd.special(7) for details about these target units.

On first boot, systemd will enable or disable units according to preset policy. See systemd.preset(5) and "First Boot Semantics" in machine-id(5).


๐Ÿงš Memory management (systemd is NOT a hoarder)

systemd only keeps a minimal set of units loaded into memory. Specifically, the only units that are kept loaded into memory are those for which at least one of the following conditions is true:

  1. It is in an active, activating, deactivating or failed state (i.e. in any unit state except for "inactive")
  2. It has a job queued for it
  3. It is a dependency of at least one other unit that is loaded into memory
  4. It has some form of resource still allocated (e.g. a service unit that is inactive but for which a process is still lingering that ignored the request to be terminated) ๐Ÿ˜ค
  5. It has been pinned into memory programmatically by a D-Bus call

systemd will automatically and implicitly load units from disk โ€” if they are not loaded yet โ€” as soon as operations are requested for them. So like, in many respects, the fact of whether a unit is loaded or not is genuinely invisible to clients. Use systemctl list-units --all to comprehensively list all units currently loaded. Any unit for which none of the conditions above applies is promptly unloaded. Bye bestie ๐Ÿ‘‹

Note that when a unit is unloaded from memory its accounting data is flushed out too. However, this data is generally not lost, because a journal log record is generated declaring the consumed resources whenever a unit shuts down. So it's fine. It's fine. ๐Ÿซถ

๐Ÿ“ Cgroups, the group chat nobody asked for but everyone needed

Processes systemd spawns are placed in individual Linux control groups named after the unit which they belong to, in the private systemd hierarchy. (See Control Groups v2[4] for more information about control groups, or short "cgroups" โ€” yes, everyone calls them cgroups, that's just the vibe.)

systemd uses this to effectively keep track of processes. Control group information is maintained in the kernel, and is accessible via the file system hierarchy (beneath /sys/fs/cgroup/), or in tools such as systemd-cgls(1) or ps(1). And pro tip from the original, verbatim: ps xawf -eo pid,user,cgroup,args is particularly useful to list all processes and the systemd units they belong to. ๐Ÿ“‹โœจ


Oh and btw bestie โ€” systemd is also compatible with a bunch of classic Unix stuff you already know and love, like /etc/fstab and the utmp database. It plays nice. ๐Ÿ’–


๐Ÿ”„ the transaction thing (aka systemd's lil queuing system)

systemd has what's called a minimal transaction system, and it's genuinely so smart of it. Here's the tea: whenever a unit is asked to start up or shut down, systemd adds that unit and all its dependencies into a temporary transaction. โœจ

Then it does a vibe check ๐Ÿ•ต๏ธโ™€๏ธ on that transaction to see if it's consistent โ€” meaning, does the ordering of all the units come out cycle-free? If it's not consistent, systemd tries to fix it up, and it drops the non-essential jobs that might be the ones creating the loop. It also tries to suppress non-essential jobs that would stop a running service (rude behavior, honestly). Finally, it checks whether the jobs in the transaction contradict jobs that are already queued, and if they do, it'll optionally just abort the whole transaction then and there.

If everything works out and the transaction is consistent and minimized in its impact, it gets merged with all the already-outstanding jobs and added to the run queue. So effectively: before systemd executes any requested operation, it verifies that the operation actually makes sense, fixes it if it can, and only fails if it really, truly cannot work. Protective king. ๐Ÿ‘‘

โš ๏ธ Important note, don't skip this: transactions are generated independently of a unit's state at runtime. So for example, if a start job is requested on an already started unit, it will still generate a transaction and wake up any inactive dependencies (and cause propagation of other jobs as per the defined relationships). Why? Because the enqueued job gets compared to the target unit's state at the time of execution, and it's marked successful and complete when both satisfy. However, that job also pulls in other dependencies due to the defined relationships, and thus leads to โ€” in our example โ€” start jobs for any of those inactive units getting queued as well. Chain reaction, but make it intentional. ๐Ÿ’…

Units may also be generated dynamically at boot time and at system manager reload time โ€” for example based on other configuration files, or based on parameters passed on the kernel command line. For the nitty gritty on that, go see systemd.generator(7). ๐Ÿฆ‹


๐Ÿ“ DIRECTORIES

System unit directories

The systemd system manager reads unit configuration from a whole bunch of different directories. So if a package wants to install unit files, it shall place them in the directory that gets returned by this:

pkg-config systemd --variable=systemdsystemunitdir

Other directories that get checked are /usr/local/lib/systemd/system and /usr/lib/systemd/system. ๐Ÿ—‚๏ธ

User configuration ALWAYS takes precedence. Periodt. And this next one gives you the path of the system configuration directory:

pkg-config systemd --variable=systemdsystemconfdir

Packages should only ever mess with the content of these directories using the enable and disable commands of the systemctl(1) tool โ€” don't be out here editing by hand, bestie, it's not the move. ๐Ÿ™ˆ The full list of directories is provided over in systemd.unit(5).

User unit directories

Similar rules apply for the user unit directories. However, here the XDG Base Directory specification[5] is what's followed to find units. โœจ

Applications should place their unit files in the directory returned by:

pkg-config systemd --variable=systemduserunitdir

And global configuration gets done in the directory reported by:

pkg-config systemd --variable=systemduserconfdir

The enable and disable commands of the systemctl(1) tool can handle both global (i.e. for all users) and private (for one user) enabling/disabling of units. Versatile. ๐Ÿซถ And again โ€” full list of directories lives in systemd.unit(5).


๐Ÿšจ SIGNALS

The service listens to a whole stack of UNIX process signals that can be used to request various actions asynchronously. Obsessed with an async queen. ๐Ÿ’…

Signal handling is enabled very early during boot, before any further processes are invoked. However โ€” and this part matters โ€” a supervising container manager or similar that wants to request these operations via this mechanism has to take into consideration that this functionality is not available during the earliest initialization phase. So don't come for it too early, it won't answer. ๐Ÿ˜ญ

An sd_notify() notification message carrying the X_SYSTEMD_SIGNALS_LEVEL=2 field gets emitted once the signal handlers are enabled, see below. You can use that to schedule submission of these signals correctly. Timing is everything, iykyk. โฐ


  • SIGTERM โ€” On receiving this signal, the systemd system manager serializes its state, reexecutes itself, and then deserializes the saved state again. This is mostly equivalent to systemctl daemon-reexec. systemd user managers will start the exit.target unit when this signal is received. That's mostly equivalent to systemctl --user start exit.target --job-mode=replace-irreversibly.
  • SIGINT โ€” On receiving this signal, the systemd system manager will start the ctrl-alt-del.target unit. Mostly equivalent to systemctl start ctrl-alt-del.target --job-mode=replace-irreversibly. If this signal is received more than 7 times per 2s, an immediate reboot gets triggered. ๐Ÿ”ฅ Note that pressing Ctrl+Alt+Del on the console triggers this signal. Hence โ€” if a reboot is hanging, pressing Ctrl+Alt+Del more than 7 times in 2 seconds is a relatively safe way to trigger an immediate reboot. (Relatively. It said relatively.) systemd user managers treat this signal the same way as SIGTERM.
  • SIGWINCH โ€” When this signal is received, the systemd system manager will start the kbrequest.target unit. Mostly equivalent to systemctl start kbrequest.target. This signal is ignored by systemd user managers.
  • SIGPWR โ€” When this signal is received, the systemd manager will start the sigpwr.target unit. Mostly equivalent to systemctl start sigpwr.target.
  • SIGUSR1 โ€” When this signal is received, the systemd manager will try to reconnect to the D-Bus bus. ๐Ÿ”Œ
  • SIGUSR2 โ€” When this signal is received, the systemd manager will log its complete state in human-readable form. The data logged is the same as what's printed by systemd-analyze dump.
  • SIGHUP โ€” Reloads the complete daemon configuration. Mostly equivalent to systemctl daemon-reload.
  • SIGRTMIN+0 โ€” Enters default mode, starts the default.target unit. Mostly equivalent to systemctl isolate default.target.
  • SIGRTMIN+1 โ€” Enters rescue mode, starts the rescue.target unit. Mostly equivalent to systemctl isolate rescue.target.
  • SIGRTMIN+2 โ€” Enters emergency mode, starts the emergency.service unit. Mostly equivalent to systemctl isolate emergency.service.
  • SIGRTMIN+3 โ€” Halts the machine, starts the halt.target unit. Mostly equivalent to systemctl start halt.target --job-mode=replace-irreversibly.
  • SIGRTMIN+4 โ€” Powers off the machine, starts the poweroff.target unit. Mostly equivalent to systemctl start poweroff.target --job-mode=replace-irreversibly.
  • SIGRTMIN+5 โ€” Reboots the machine, starts the reboot.target unit. Mostly equivalent to systemctl start reboot.target --job-mode=replace-irreversibly.
  • SIGRTMIN+6 โ€” Reboots the machine via kexec, starts the kexec.target unit. Mostly equivalent to systemctl start kexec.target --job-mode=replace-irreversibly.
  • SIGRTMIN+7 โ€” Reboots userspace, starts the soft-reboot.target unit. Mostly equivalent to systemctl start soft-reboot.target --job-mode=replace-irreversibly. Added in version 254.
  • SIGRTMIN+13 โ€” Immediately halts the machine. ๐Ÿ’€
  • SIGRTMIN+14 โ€” Immediately powers off the machine.
  • SIGRTMIN+15 โ€” Immediately reboots the machine.
  • SIGRTMIN+16 โ€” Immediately reboots the machine with kexec.
  • SIGRTMIN+17 โ€” Immediately reboots the userspace. Added in version 254.
  • SIGRTMIN+20 โ€” Enables display of status messages on the console, as controlled via systemd.show_status=1 on the kernel command line. You may want to use SetShowStatus() instead of SIGRTMIN+20 in order to prevent race conditions. See org.freedesktop.systemd1(5).
  • SIGRTMIN+21 โ€” Disables display of status messages on the console, as controlled via systemd.show_status=0 on the kernel command line. You may want to use SetShowStatus() instead of SIGRTMIN+21 in order to prevent race conditions. See org.freedesktop.systemd1(5).
  • SIGRTMIN+22 โ€” Sets the service manager's log level to "debug", in a fashion equivalent to systemd.log_level=debug on the kernel command line. ๐Ÿ›
  • SIGRTMIN+23 โ€” Restores the log level to its configured value. That configured value is derived from โ€” in order of priority โ€” the value specified with systemd.log-level= on the kernel command line, or the value specified with LogLevel= in the configuration file, or the built-in default of "info". Added in version 239.
  • SIGRTMIN+24 โ€” Immediately exits the manager (only available for --user instances). ๐Ÿ‘‹ Added in version 195.
  • SIGRTMIN+25 โ€” On receiving this signal, the systemd manager will reexecute itself. Mostly equivalent to systemctl daemon-reexec, except that it gets done asynchronously. The systemd system manager treats this signal the same way as SIGTERM. Added in version 250.
  • SIGRTMIN+26 โ€” Restores the log target to its configured value. The configured value is derived from โ€” in order of priority โ€” the value specified with systemd.log-target= on the kernel command line, or the value specified with LogTarget= in the configuration file, or the built-in default. Added in version 239.
  • SIGRTMIN+27, SIGRTMIN+28 โ€” Sets the log target to "console" on SIGRTMIN+27 (or "kmsg" on SIGRTMIN+28), in a fashion equivalent to systemd.log_target=console (or systemd.log_target=kmsg on SIGRTMIN+28) on the kernel command line. Added in version 239.

๐ŸŒˆ ENVIRONMENT ๐ŸŒˆ

okay bestie so the environment block for the system manager? it does not start out cute and empty โ€” the kernel sets it up initially. and when you write key=value assignments on the kernel command line, those get turned into environment variables for PID 1, fr fr. ๐Ÿซถ

for the user manager, the system manager hands it the environment as described in the "Environment Variables in Spawned Processes" section of systemd.exec(5). and listen โ€” the DefaultEnvironment= setting in the system manager applies to all services, including user@.service. that's iconic. โœจ

you can also add extra entries (just like for any other service) through the Environment= and EnvironmentFile= settings on user@.service (go read systemd.exec(5)), and you can set additional environment variables through the ManagerEnvironment= setting in systemd-system.conf(5) and systemd-user.conf(5). so many doors, same house. ๐Ÿ’…

here's a lil rundown of some of the variables systemd understands:


$SYSTEMD_LOG_LEVEL

the maximum log level of emitted messages โ€” meaning messages with a higher log level (i.e. the less important ones) get suppressed. it takes a comma-separated list of values. each value is either one of these, listed in order of decreasing importance: emerg, alert, crit, err, warning, notice, info, debug โ€” or just an integer in the range 0...7. see syslog(3) for more info.

each value may optionally be prefixed with one of console, syslog, kmsg or journal followed by a colon, which sets the maximum log level for that specific log target. like this, bestie:

SYSTEMD_LOG_LEVEL=debug,console:info

that says log at debug level, except when logging to the console, where it should be at info level. but note!! the global maximum log level takes priority over any per-target maximum log levels. periodt.

this can be overridden with --log-level=.

$SYSTEMD_LOG_COLOR

a boolean. if true, messages written to the tty get colored according to priority. ๐ŸŒˆ

this can be overridden with --log-color=.

$SYSTEMD_LOG_TIME

a boolean. if true, console log messages get prefixed with a timestamp. โฐ

this can be overridden with --log-time=.

Added in version 246.

$SYSTEMD_LOG_LOCATION

a boolean. if true, messages get prefixed with a filename and line number in the source code where the message originates. so you can see exactly where it came from, iykyk. ๐Ÿ”

this can be overridden with --log-location=.

$SYSTEMD_LOG_TID

a boolean. if true, messages get prefixed with the current numerical thread ID (TID).

Added in version 247.

$SYSTEMD_LOG_TARGET

where your log messages go, bestie. one of:

  • console โ€” log to the attached tty
  • console-prefixed โ€” log to the attached tty but with prefixes encoding the log level and "facility", see syslog(3)
  • kmsg โ€” log to the kernel circular log buffer
  • journal โ€” log to the journal
  • journal-or-kmsg โ€” log to the journal if available, and to kmsg otherwise
  • auto โ€” determine the appropriate log target automatically, this is the default
  • null โ€” disable log output entirely (silence era, honestly)

this can be overridden with --log-target=.

$SYSTEMD_LOG_RATELIMIT_KMSG

whether to ratelimit kmsg or not. takes a boolean. defaults to "true". if disabled, systemd will not ratelimit messages written to kmsg. no cap.

Added in version 254.

$XDG_CONFIG_HOME, $XDG_CONFIG_DIRS, $XDG_DATA_HOME, $XDG_DATA_DIRS

the systemd user manager uses these variables in accordance to the XDG Base Directory specification[5] to find its configuration. home is where the config is. ๐Ÿ 

$SYSTEMD_UNIT_PATH, $SYSTEMD_GENERATOR_PATH, $SYSTEMD_ENVIRONMENT_GENERATOR_PATH

these control where systemd looks for unit files and generators. they may contain a list of paths, separated by colons (":"). when set, if the list ends with an empty component ("...:"), the list is prepended to the usual set of paths. otherwise, the list you specified replaces the usual set of paths. so that trailing colon is doing a whole lot of work, lowkey. ๐Ÿ‘‘

$SYSTEMD_PAGER, $PAGER

which pager to use when --no-pager isn't given. $SYSTEMD_PAGER is used if it's set; otherwise $PAGER gets the job. if neither $SYSTEMD_PAGER nor $PAGER are set, a set of well-known pager implementations is tried in turn โ€” including less(1) and more(1) โ€” until one is found. if no pager implementation is discovered at all, no pager gets invoked. setting either of these environment variables to an empty string or to the value "cat" is equivalent to passing --no-pager.

Note: if $SYSTEMD_PAGERSECURE is not set, $SYSTEMD_PAGER and $PAGER can only be used to disable the pager (with "cat" or ""), and are otherwise ignored. big deal, remember this one.

$SYSTEMD_LESS

override the options passed to less (by default "FRSXMK").

users might want to change two options in particular:

  • K โ€” this option instructs the pager to exit immediately when Ctrl+C is pressed. to allow less to handle Ctrl+C itself so it can switch back to the pager command prompt, you unset this option. if the value of $SYSTEMD_LESS does not include "K", and the pager that gets invoked is less, then Ctrl+C will be ignored by the executable, and needs to be handled by the pager.
  • X โ€” this option instructs the pager to not send termcap initialization and deinitialization strings to the terminal. it's set by default to allow command output to remain visible in the terminal even after the pager exits. nevertheless, this prevents some pager functionality from working โ€” in particular, paged output cannot be scrolled with the mouse. ๐Ÿ˜ญ

note that setting the regular $LESS environment variable has no effect for less invocations made by systemd tools. see less(1) for more discussion.

$SYSTEMD_LESSCHARSET

override the charset passed to less (by default "utf-8", if the invoking terminal is determined to be UTF-8 compatible). ๐ŸŒธ

note that setting the regular $LESSCHARSET environment variable has no effect for less invocations by systemd tools. same energy as above.

$SYSTEMD_PAGERSECURE

okay this one is the important one, bestie, sit down. โ˜•

common pager commands like less(1), in addition to just "paging" โ€” i.e. scrolling through the output โ€” support opening of or writing to other files and running arbitrary shell commands. when commands are invoked with elevated privileges, for example under sudo(8) or pkexec(1), the pager becomes a security boundary. care must be taken that only programs with strictly limited functionality are used as pagers, and that unintended interactive features โ€” like opening or creation of new files, or starting of subprocesses โ€” are not allowed. "Secure mode" for the pager may be enabled as described below, if the pager supports that (and ngl, most pagers are not written in a way that takes this into consideration ๐Ÿ’€). it is recommended to either explicitly enable "secure mode" or to completely disable the pager using --no-pager or PAGER=cat when allowing untrusted users to execute commands with elevated privileges.

this option takes a boolean argument. when set to true, the "secure mode" of the pager is enabled. in "secure mode", LESSSECURE=1 will be set when invoking the pager, which instructs the pager to disable commands that open or create new files or start new subprocesses. currently only less(1) is known to understand this variable and implement "secure mode".

when set to false, no limitation is placed on the pager. setting SYSTEMD_PAGERSECURE=0 or not removing it from the inherited environment may allow the user to invoke arbitrary commands. โš ๏ธ

when $SYSTEMD_PAGERSECURE is not set, systemd tools attempt to automatically figure out if "secure mode" should be enabled and whether the pager supports it. "secure mode" is enabled if the effective UID is not the same as the owner of the login session โ€” see geteuid(2) and sd_pid_get_owner_uid(3) โ€” or when running under sudo(8) or similar tools ($SUDO_UID is set [6]). in those cases, SYSTEMD_PAGERSECURE=1 will be set and pagers which are not known to implement "secure mode" will not be used at all. note that this autodetection only covers the most common mechanisms to elevate privileges and is intended as convenience. it is recommended to explicitly set $SYSTEMD_PAGERSECURE or disable the pager.

note that if $SYSTEMD_PAGER or $PAGER variables are to be honoured, other than to disable the pager, $SYSTEMD_PAGERSECURE must be set too. ๐Ÿ”

$SYSTEMD_COLORS

takes a boolean argument. when true, systemd and related utilities use colors in their output; otherwise the output will be monochrome. additionally, this variable can take one of the following special values: "16", "256" โ€” to restrict the use of colors to the base 16 or 256 ANSI colors, respectively. this can be specified to override the automatic decision based on $TERM and what the console is connected to. ๐ŸŽจ

$SYSTEMD_URLIFY

the value must be a boolean. this controls whether clickable links should be generated in the output, for terminal emulators that support it. this can be specified to override the decision systemd makes based on $TERM and other conditions. ๐Ÿ”—

$LISTEN_PID, $LISTEN_PIDFDID, $LISTEN_FDS, $LISTEN_FDNAMES

set by systemd for supervised processes during socket-based activation. see sd_listen_fds(3) for more information. ๐Ÿงฆ

$NOTIFY_SOCKET

set by the service manager for its services, for status and readiness notifications. it's also consumed by the service manager for notifying supervising container managers or service managers further up the stack about its own progress. see sd_notify(3) and the relevant section below for more information. ๐Ÿ“ฃ


for further environment variables understood by systemd and its various components, see Known Environment Variables[7]. there's always more lore. ๐Ÿฆ‹

๐Ÿฆ‹ KERNEL COMMAND LINE ๐Ÿฆ‹

okay so when systemd runs as the system instance, it reads a whole lil list of options, right? and where it reads them from depends on the vibe of the environment it's living in. so here's the tea:

  • if you're inside a Linux container, these options get parsed from the command line arguments passed to systemd itself โ€” right next to any of the command line options from the Options section up above ๐Ÿ’…
  • if you're outside</> of Linux containers, the arguments get parsed from /proc/cmdline instead

the following variables are understood, bestie:

  • systemd.unit=, rd.systemd.unit= โ€” overrides which unit gets activated on boot. defaults to default.target. you can use this to temporarily boot into a different boot unit, like rescue.target or emergency.service. peep systemd.special(7) for the deets on those units. the one prefixed with rd. is honored only in the initrd, while the non-prefixed one is honored only in the main system. โœจ
  • systemd.dump_core โ€” takes a boolean argument, or just enables the option if you specify it with no argument at all. if enabled, the systemd manager (PID 1) dumps core when it crashes. otherwise? no core dump, no drama. defaults to enabled.

Added in version 233.

  • systemd.crash_chvt โ€” takes a positive integer, or a boolean argument. can also be specified with no argument, with the same effect as a positive boolean. if you give it a positive integer (in the range 1โ€“63), the system manager (PID 1) will activate that specified virtual terminal when it crashes. defaults to disabled, meaning no such switch is attempted. if set to enabled, it uses the virtual terminal the kernel messages are written to instead.

Added in version 233.

  • systemd.crash_shell โ€” takes a boolean argument, or enables the option if specified with no argument. if enabled, the system manager (PID 1) spawns a shell when it crashes. otherwise, no shell. defaults to disabled, for security reasons, because that shell is not protected by password authentication. so like, be careful bestie ๐Ÿ˜ญ

Added in version 233.

  • systemd.crash_action= โ€” takes one of "freeze", "reboot" or "poweroff". defaults to "freeze". if set to "freeze", the system will hang indefinitely when the system manager (PID 1) crashes. if set to "reboot", the system manager (PID 1) will reboot the machine automatically when it crashes, after a 10s delay. if set to "poweroff", the system manager (PID 1) will power off the machine immediately when it crashes. and if you combine this with systemd.crash_shell, the configured crash action is executed after the shell exits.

Added in version 256.

  • systemd.confirm_spawn โ€” takes a boolean argument, or a path to the virtual console where the confirmation messages should be emitted. can also be specified with no argument, with the same effect as a positive boolean. if enabled, the system manager (PID 1) asks for confirmation when spawning processes using /dev/console. if a path or a console name (like "ttyS0") is provided, the virtual console pointed to by that path or described by the given name is used instead. defaults to disabled.

Added in version 233.

  • systemd.service_watchdogs= โ€” takes a boolean argument. if disabled, all service runtime watchdogs (WatchdogSec=) and emergency actions (e.g. OnFailure= or StartLimitAction=) are ignored by the system manager (PID 1); see systemd.service(5). defaults to enabled, i.e. watchdogs and failure actions are processed normally. the hardware watchdog is not affected by this option, jsyk.

Added in version 237.

  • systemd.show_status โ€” takes a boolean argument or the constants error and auto. can also be specified with no argument, with the same effect as a positive boolean. if enabled, the systemd manager (PID 1) shows terse service status updates on the console during bootup. with error, only messages about failures are shown, but boot is otherwise quiet. auto behaves like false until there's a significant delay in boot. defaults to enabled, unless quiet is passed as a kernel command line option โ€” in which case it defaults to error. if specified, it overrides the system manager configuration file option ShowStatus=, see systemd-system.conf(5).

Added in version 233.

  • systemd.status_unit_format= โ€” takes name, description or combined as the value. if name, the system manager will use unit names in status messages. if combined, the system manager will use unit names and description in status messages. when specified, overrides the system manager configuration file option StatusUnitFormat=, see systemd-system.conf(5).

Added in version 243.

  • systemd.log_color, systemd.log_level=, systemd.log_location, systemd.log_target=, systemd.log_time, systemd.log_tid, systemd.log_ratelimit_kmsg โ€” controls log output, with the exact same effect as the $SYSTEMD_LOG_COLOR, $SYSTEMD_LOG_LEVEL, $SYSTEMD_LOG_LOCATION, $SYSTEMD_LOG_TARGET, $SYSTEMD_LOG_TIME, $SYSTEMD_LOG_TID and $SYSTEMD_LOG_RATELIMIT_KMSG environment variables described up above. note that systemd.log_color, systemd.log_location, systemd.log_time, systemd.log_tid and systemd.log_ratelimit_kmsg can be specified with no argument, with the same effect as a positive boolean. ๐ŸŽ€
  • systemd.default_standard_output=, systemd.default_standard_error= โ€” controls the default standard output and error output for services and sockets. like, it controls the default for StandardOutput= and StandardError= (see systemd.exec(5) for the whole story). takes one of inherit, null, tty, journal, journal+console, kmsg, kmsg+console. if the argument is omitted, systemd.default-standard-output= defaults to journal and systemd.default-standard-error= defaults to inherit. ๐Ÿ’œ
  • systemd.setenv= โ€” takes a string argument in the form VARIABLE=VALUE. you can use this to set default environment variables that get added to forked child processes. you can use it more than once to set multiple variables, slay. โœจ
  • systemd.machine_id= โ€” takes a 32 character hex value to be used for setting the machine-id. intended mostly for network booting, where you want the same machine-id for every single boot.

Added in version 229.

  • systemd.set_credential=, systemd.set_credential_binary= โ€” sets a system credential, which can then be propagated to system services using the ImportCredential= or LoadCredential= setting, see systemd.exec(5) for details. takes a pair of credential name and value, separated by a colon. the systemd.set_credential= parameter expects the credential value in literal text form, while the systemd.set_credential_binary= parameter takes binary data encoded in Base64. okay so important: the kernel command line is typically accessible by unprivileged programs in /proc/cmdline. so bestie, this mechanism is not suitable for transferring sensitive data ๐Ÿ™ˆ use it only for data that isn't sensitive (like public keys/certificates, rather than private keys), or in testing/debugging environments. periodt.

for further info, see the System and Service Credentials[8] documentation.

Added in version 251.

  • systemd.import_credentials= โ€” takes a boolean argument. if false, it disables importing credentials from the kernel command line, the DMI/SMBIOS OEM string table, the qemu_fw_cfg subsystem or the EFI kernel stub.

Added in version 251.

  • quiet โ€” turns off status output at boot, much like systemd.show_status=no would. note that this option is also read by the kernel itself and disables kernel log output. so passing this option turns off the usual output from both the system manager and the kernel. ๐Ÿคซ

Added in version 186.

  • debug โ€” turns on debugging output. this is equivalent to systemd.log_level=debug. note that this option is also read by the kernel itself and enables kernel debug output. so passing this option turns on the debug output from both the system manager and the kernel. ๐Ÿ”ฅ

Added in version 205.

  • emergency, rd.emergency โ€” boot into emergency mode. these options are equivalent to systemd.unit=emergency.target or rd.systemd.unit=emergency.target, respectively. they were initially provided for compatibility with SysV, but they're retained as convenient shortcuts. ๐Ÿ‘‘

Added in version 186.

  • rescue, rd.rescue, single, 1 โ€” boot into rescue mode. these options are equivalent to either systemd.unit=rescue.target or rd.systemd.unit=rescue.target. they were initially provided for compatibility with SysV, but they're retained as convenient shortcuts. ๐Ÿ’…

Added in version 186.

  • 3, 5 โ€” shortcuts to boot into specific targets: 3 is equivalent to systemd.unit=multi-user.target and 5 is equivalent to systemd.unit=graphical.target. these were initially provided for compatibility with SysV, but they're retained as convenient shortcuts.

Added in version 186.

  • locale.LANG=, locale.LANGUAGE=, locale.LC_CTYPE=, locale.LC_NUMERIC=, locale.LC_TIME=, locale.LC_COLLATE=, locale.LC_MONETARY=, locale.LC_MESSAGES=, locale.LC_PAPER=, locale.LC_NAME=, locale.LC_ADDRESS=, locale.LC_TELEPHONE=, locale.LC_MEASUREMENT=, locale.LC_IDENTIFICATION= โ€” set the system locale to use. this overrides the settings in /etc/locale.conf. for more information, see locale.conf(5) and locale(7). ๐ŸŒˆ

Added in version 186.

and for any other kernel command line parameters understood by components of the core OS, please refer to kernel-command-line(7). ๐Ÿซถ


๐Ÿ”‘ SYSTEM CREDENTIALS ๐Ÿ”‘

okay so during init the service manager is gonna import credentials from a bunch of different sources into the system's set of credentials, and then those can get propagated into services and eaten up by generators. here's the whole rundown bestie:

  • When the service manager first initializes, it reads system credentials from SMBIOS Type 11 vendor strings io.systemd.credential:name=value, and io.systemd.credential.binary:name=value.
  • At the same exact time it also imports credentials from QEMU "fw_cfg". (quick note: the SMBIOS mechanism is generally preferred, because it's faster and generic. ๐Ÿ’…)
  • Credentials may be passed via the kernel command line, using the systemd.set-credential= parameter, see above.
  • Credentials may be passed from the UEFI environment via systemd-stub(7).
  • When the service manager is invoked during the initrd โ†’ host transition it will import all files in /run/credentials/@initrd/ as system credentials.

wanna see the list of credentials that got passed into your system? run systemd-creds(1) like this:

# systemd-creds --system list

for more deets see the System and Service Credentials[8] documentation. โœจ


so when the service manager is running as PID 1, it consumes these system credentials right here:

  • vmm.notify_socket โ€” contains an AF_VSOCK or AF_UNIX address where to send a READY=1 notification message when the service manager has completed booting. See sd_notify(3) and the next section for more info. heads up: if the hypervisor does not support SOCK_DGRAM over AF_VSOCK, SOCK_SEQPACKET will be tried instead. the credential payload for AF_VSOCK should be a string in the form "vsock:CID:PORT". "vsock-stream", "vsock-dgram" and "vsock-seqpacket" can be used instead of "vsock" to force usage of the corresponding socket type.

This feature is useful for machine managers or other processes on the host to receive a notification via VSOCK when a virtual machine has finished booting. ๐Ÿฆ‹

Added in version 254.

  • system.machine_id โ€” takes a 128bit hexadecimal ID to initialize /etc/machine-id from, if the file is not set up yet. See machine-id(5) for details. ๐Ÿ’–

Added in version 254.

For a list of system credentials that various other components of systemd consume, see systemd.system-credentials(7). โœจ


๐Ÿ“ฃ READINESS PROTOCOL ๐Ÿ“ฃ

ngl this one's kinda iconic. the service manager implements a readiness notification protocol both between the manager and its services (i.e. down the stack), and between the manager and a potential supervisor further up the stack (which could be a machine or container manager, or in case of a per-user service manager, the system service manager instance). the basic protocol (and the suggested API for it) is described in sd_notify(3). ๐Ÿซถ

The notification socket the service manager (including PID 1) uses for reporting readiness to its own supervisor is set via the usual $NOTIFY_SOCKET environment variable (see above). Since this is directly settable only for container managers and for the per-user instance of the service manager, an additional mechanism to configure this is available, in particular intended for use in VM environments: the vmm.notify_socket system credential (see above) may be set to a suitable socket (typically an AF_VSOCK one) via SMBIOS Type 11 vendor strings. For details see above. ๐Ÿ’…

okay so the notification protocol going from the service manager up the stack towards a supervisor supports a bunch of extension fields that let a supervisor learn about specific properties of the system and track its boot progress. specifically, these fields get sent:

  • An X_SYSTEMD_HOSTNAME=... message will be sent out once the initial hostname for the system has been determined. note that during later runtime the hostname might be changed again programmatically, and (currently) no further notifications are sent out in that case. ๐Ÿ˜ญ

Added in version 256.

  • An X_SYSTEMD_MACHINE_ID=... message will be sent out once the machine ID of the system has been determined. See machine-id(5) for details.

Added in version 256.

  • An X_SYSTEMD_SIGNALS_LEVEL=... message will be sent out once the service manager installed the various UNIX process signal handlers described above. the field's value is an unsigned integer formatted as decimal string, and it indicates the supported UNIX process signal feature level of the service manager. currently, only a single feature level is defined:
    • X_SYSTEMD_SIGNALS_LEVEL=2 covers the various UNIX process signals documented above โ€“ which are a superset of those supported by the historical SysV init system.

โš ๏ธ signals sent to PID 1 before this message is sent might not be handled correctly yet. A consumer of these messages should parse the value as an unsigned integer that indicates the level of support. For now only the mentioned level 2 is defined, but later on additional levels might be defined with higher integers, that will implement a superset of the currently defined behaviour. ๐Ÿ‘‘

Added in version 256.

  • X_SYSTEMD_UNIT_ACTIVE=... and X_SYSTEMD_UNIT_INACTIVE=... messages will be sent out for each target unit as it becomes active or stops being active. this is useful to track boot progress and functionality. for example, once the ssh-access.target unit is reported started, SSH access is typically available, see systemd.special(7) for details. โœจ

Added in version 256.

  • An X_SYSTEMD_SHUTDOWN=... message will be sent out very shortly before the system shuts down. the value is one of the strings "reboot", "halt", "poweroff", "kexec" and indicates which kind of shutdown is being executed. ๐Ÿ’€

Added in version 256.

  • An X_SYSTEMD_REBOOT_PARAMETER=... message will also be sent out very shortly before the system shuts down. its value is the reboot argument as configured with systemctl --reboot-argument=....

Added in version 256.

psst โ€” note that these extension fields are sent in addition to the regular "READY=1" and "RELOADING=1" notifications. ๐ŸŒˆ

โœจ OPTIONS โœจ

okay so real talk bestie: you will almost never run systemd by hand ๐Ÿ’…. it boots up mad early and it's already running by the time you, a whole human, could even type at it. when you wanna boss it around you use tools like systemctl(1), periodt. so because direct invocation is basically a special-occasion thing, all the options below are mostly for debugging and other special purposes ๐Ÿฆ‹.

๐Ÿ” Introspection and debugging options

these ones are for testing and peeking inside ๐Ÿ‘€ โ€” and systemd can be invoked with them at any time:

  • --dump-configuration-items โ€” dumps all the unit configuration items it understands ๐Ÿ’–. it spits out a terse but complete list of every configuration item understood in unit definition files.
  • --dump-bus-properties โ€” dumps the bus properties it exposes โœจ. terse but complete list of every property exposed on D-Bus. Added in version 239.
  • --test โ€” figures out the initial start-up transaction (aka the list of jobs enqueued at start-up), dumps it, and dips โ€” without actually executing any of the determined jobs. this is a debugging-only flex ngl. heads up though: during regular service manager start-up, extra units that this operation doesn't show may get started anyway, because hardware, socket, bus or other kinds of activation might add additional jobs as the transaction is executed ๐Ÿ˜ญ. use --system to ask for the initial transaction of the system service manager (this is also the implied default), or combine it with --user to ask for the initial transaction of the per-user service manager instead.
  • --system, --user โ€” when you use these with --test, they pick whether you're calculating the initial transaction for the system instance or for a per-user instance ๐Ÿ‘‘. without --test they do literally nothing, because during regular (i.e. non---test) invocations the service manager just auto-detects whether it should run in system or per-user mode by checking whether the PID it's run as is 1 or not. note: booting and maintaining a system with the service manager running in --system mode but with a PID other than 1 is not supported. don't do it ๐Ÿ™ˆ.
  • -h, --help โ€” prints a short help text and exits. the classic ๐ŸŽ€.
  • --version โ€” prints a short version string and exits โญ.

๐Ÿงญ Options that duplicate kernel command line settings

these options map one-to-one onto the options listed above in "Kernel Command Line" ๐ŸŒˆ. for the system manager both forms work exactly the same, but the glow-up recommendation is to use the forms listed above in this context, because they're properly namespaced ๐Ÿ’…. and if an option shows up both on the kernel command line and as a normal command line argument, the latter wins โ€” higher precedence, no cap.

when systemd runs as a user manager, the kernel command line is completely ignored and only the options described below are understood ๐Ÿฆ‹. still, systemd is usually started in this mode through the user@.service(5) service, which is shared between all users. it may be more convenient to use configuration files to tweak settings (see systemd-user.conf(5)), or environment variables ๐ŸŒธ. see the "Environment" section above for the whole discussion on how the environment block gets set.

  • --unit= โ€” set the default unit to activate on startup. if you don't specify it, it defaults to default.target. see systemd.unit= above ๐Ÿ’œ.
  • --dump-core โ€” enable core dumping on crash ๐Ÿ’€. this switch has no effect when running as a user instance. same as systemd.dump_core= above.
  • --crash-vt=VT โ€” switch to a specific virtual console (VT) on crash. no effect when running as a user instance. same as systemd.crash_chvt= above (but not the different spelling!). Added in version 227.
  • --crash-shell โ€” run a shell on crash ๐Ÿš. no effect when running as a user instance. see systemd.crash_shell= above.
  • --crash-action= โ€” specify what to do when the system manager (PID 1) crashes. no effect when systemd is running as a user instance. see systemd.crash_action= above. Added in version 256.
  • --confirm-spawn โ€” ask for confirmation when spawning processes ๐Ÿ™‹. no effect when run as a user instance. see systemd.confirm_spawn above.
  • --show-status โ€” show terse unit status info on the console during boot-up and shutdown. see systemd.show_status above. Added in version 244.
  • --log-color โ€” highlight important log messages ๐ŸŽจ. see systemd.log_color above. Added in version 244.
  • --log-level= โ€” set the log level. see systemd.log_level above.
  • --log-location โ€” include code location in log messages ๐Ÿ“. see systemd.log_location above. Added in version 244.
  • --log-target= โ€” set the log target. see systemd.log_target above.
  • --log-time= โ€” prefix console messages with a timestamp โฐ. see systemd.log_time above. Added in version 246.
  • --machine-id= โ€” override the machine-id set on the hard drive. see systemd.machine_id= above. Added in version 229.
  • --service-watchdogs โ€” globally enable/disable all service watchdog timeouts and emergency actions ๐Ÿ•. see systemd.service_watchdogs above. Added in version 237.
  • --default-standard-output=, --default-standard-error= โ€” sets the default output or error output for all services and sockets, respectively. see systemd.default_standard_output= and systemd.default_standard_error= above.

โณ SYSTEM CLOCK EPOCH โณ

when systemd is started or restarted, it may set the system clock to the "epoch" โœจ. this whole mechanism exists so the system clock stays somewhat reasonably initialized and roughly monotonic across reboots โ€” like, in case no battery-backed local RTC is available, or the one you've got doesn't work correctly ๐Ÿ˜ญ. it's giving "we do our best with what we have."

the epoch is the lowest date above which the system clock time is assumed to be set correctly ๐Ÿ‘‘. when initializing, the local clock gets advanced to the epoch if it was set to a lower value. and here's the special case: if the local clock is sufficiently far in the future โ€” by default 15 years, though this can be configured at build time โ€” the hardware clock is assumed to be broken ๐Ÿ’€, and the system clock gets rewound to the epoch.

the epoch is set to the highest of these three things:

  • the build time of systemd
  • the modification time ("mtime") of /usr/lib/clock-epoch
  • the modification time of /var/lib/systemd/timesync/clock

๐Ÿ“‚ FILES ๐Ÿ“‚

  • /run/systemd/notify โ€” daemon status notification socket ๐Ÿซถ. this is an AF_UNIX datagram socket and it's used to implement the daemon notification logic as implemented by sd_notify(3).
  • /run/systemd/private โ€” used internally as the communication channel between systemctl(1) and the systemd process ๐Ÿ”’. this is an AF_UNIX stream socket. this interface is private to systemd and should not be used in external projects, fr fr.
  • /usr/lib/clock-epoch โ€” the modification time ("mtime") of this file is used for the time epoch, see the previous section โณ. Added in version 247.
  • /var/lib/systemd/timesync/clock โ€” the modification time ("mtime") of this file is updated by systemd-timesyncd.service(8) ๐Ÿ•ฐ๏ธ. if present, the modification time of the file is used for the epoch, see the previous section. Added in version 257.

๐Ÿ“œ HISTORY ๐Ÿ“œ

systemd 252 โ€” the kernel command-line arguments systemd.unified_cgroup_hierarchy and systemd.legacy_systemd_cgroup_controller were deprecated ๐Ÿ˜ญ. please switch to the unified cgroup hierarchy. like, actually please. the old way is over, bestie ๐Ÿ’….


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

the [systemd Homepage][9] ๐ŸŒ, systemd-system.conf(5), locale.conf(5), systemctl(1), journalctl(1), systemd-notify(1), daemon(7), sd-daemon(3), org.freedesktop.systemd1(5), systemd.unit(5), systemd.special(7), pkg-config(1), kernel-command-line(7), bootup(7), systemd.directives(7), org.freedesktop.systemd1(5) (yes it's listed twice, that's just how much we love it ๐Ÿซถ).

for more info about the concepts and ideas behind systemd, please refer to the [Original Design Document][10] ๐Ÿ“–.


๐Ÿ”– NOTES ๐Ÿ”–

  1. Interface Portability and Stability Promise โ€” https://systemd.io/PORTABILITY_AND_STABILITY/
  2. Container Interface โ€” https://systemd.io/CONTAINER_INTERFACE
  3. initrd Interface โ€” https://systemd.io/INITRD_INTERFACE/
  4. Control Groups v2 โ€” https://docs.kernel.org/admin-guide/cgroup-v2.html
  5. XDG Base Directory specification โ€” https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
  6. it is recommended for other tools to set and check $SUDO_UID as appropriate, treating it as a common interface ๐Ÿซก.
  7. Known Environment Variables โ€” https://systemd.io/ENVIRONMENT
  8. System and Service Credentials โ€” https://systemd.io/CREDENTIALS
  9. systemd Homepage โ€” https://systemd.io/
  10. Original Design Document โ€” https://0pointer.de/blog/projects/systemd.html

and that's a wrap on the whole SYSTEMD(1) saga, bestie ๐ŸŽ€โœจ this was systemd 259.10, i.e. the SYSTEMD(1) era of the manual page โ€” go forth and read the rest of the series, you absolute icon ๐Ÿ‘‘๐Ÿ’–

๐Ÿ“ฆ where this page comes from