| 1 |
<?xml version='1.0'?> <!--*-nxml-*--> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="systemd.swap" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 7 |
<refentryinfo> |
| 8 |
<title>systemd.swap</title> |
| 9 |
<productname>systemd</productname> |
| 10 |
</refentryinfo> |
| 11 |
|
| 12 |
<refmeta> |
| 13 |
<refentrytitle>systemd.swap</refentrytitle> |
| 14 |
<manvolnum>5</manvolnum> |
| 15 |
</refmeta> |
| 16 |
|
| 17 |
<refnamediv> |
| 18 |
<refname>systemd.swap</refname> |
| 19 |
<refpurpose>Swap unit configuration</refpurpose> |
| 20 |
</refnamediv> |
| 21 |
|
| 22 |
<refsynopsisdiv> |
| 23 |
<para><filename><replaceable>swap</replaceable>.swap</filename></para> |
| 24 |
</refsynopsisdiv> |
| 25 |
|
| 26 |
<refsect1> |
| 27 |
<title>Description</title> |
| 28 |
|
| 29 |
<para>A unit configuration file whose name ends in |
| 30 |
<literal>.swap</literal> encodes information about a swap device |
| 31 |
or file for memory paging controlled and supervised by |
| 32 |
systemd.</para> |
| 33 |
|
| 34 |
<para>This man page lists the configuration options specific to |
| 35 |
this unit type. See |
| 36 |
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 37 |
for the common options of all unit configuration files. The common |
| 38 |
configuration items are configured in the generic [Unit] and |
| 39 |
[Install] sections. The swap specific configuration options are |
| 40 |
configured in the [Swap] section.</para> |
| 41 |
|
| 42 |
<para>Additional options are listed in |
| 43 |
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
| 44 |
which define the execution environment the <citerefentry |
| 45 |
project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 46 |
program is executed in, in |
| 47 |
<citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
| 48 |
which define the way these processes are |
| 49 |
terminated, and in |
| 50 |
<citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
| 51 |
which configure resource control settings for these processes of the |
| 52 |
unit.</para> |
| 53 |
|
| 54 |
<para>Swap units must be named after the devices or files they control. Example: the swap device <filename |
| 55 |
index="false">/dev/sda5</filename> must be configured in a unit file <filename>dev-sda5.swap</filename>. For |
| 56 |
details about the escaping logic used to convert a file system path to a unit name, see |
| 57 |
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. Note that swap |
| 58 |
units cannot be templated, nor is possible to add multiple names to a swap unit by creating additional symlinks to |
| 59 |
it.</para> |
| 60 |
|
| 61 |
<para>Note that swap support on Linux is privileged, swap units are hence only available in the system |
| 62 |
service manager (and root's user service manager), but not in unprivileged user's service manager.</para> |
| 63 |
</refsect1> |
| 64 |
|
| 65 |
<refsect1> |
| 66 |
<title>Automatic Dependencies</title> |
| 67 |
|
| 68 |
<refsect2> |
| 69 |
<title>Implicit Dependencies</title> |
| 70 |
|
| 71 |
<para>The following dependencies are implicitly added:</para> |
| 72 |
|
| 73 |
<itemizedlist> |
| 74 |
<listitem><para>All swap units automatically get the |
| 75 |
<varname>Requires=</varname> and <varname>After=</varname> |
| 76 |
dependencies on the device units or the mount units of the files |
| 77 |
they are activated from.</para></listitem> |
| 78 |
</itemizedlist> |
| 79 |
|
| 80 |
<para>Additional implicit dependencies may be added as result of |
| 81 |
execution and resource control parameters as documented in |
| 82 |
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 83 |
and |
| 84 |
<citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
| 85 |
</refsect2> |
| 86 |
|
| 87 |
<refsect2> |
| 88 |
<title>Default Dependencies</title> |
| 89 |
|
| 90 |
<para>The following dependencies are added unless <varname>DefaultDependencies=no</varname> is set:</para> |
| 91 |
|
| 92 |
<itemizedlist> |
| 93 |
<listitem><para>Local swap units automatically acquire a <varname>Conflicts=</varname> and a |
| 94 |
<varname>Before=</varname> dependency on <filename>umount.target</filename> so that they are deactivated at |
| 95 |
shutdown as well as a <varname>Before=swap.target</varname> dependency.</para></listitem> |
| 96 |
|
| 97 |
<listitem><para>Network swap units (those with <option>_netdev</option> in their options) automatically acquire |
| 98 |
<varname>After=</varname> dependencies on <filename>remote-fs-pre.target</filename> and |
| 99 |
<filename>network.target</filename>, plus <varname>After=</varname> and <varname>Wants=</varname> dependencies |
| 100 |
on <filename>network-online.target</filename>, and a <varname>Before=</varname> dependency on |
| 101 |
<filename>remote-fs.target</filename> instead of <filename>swap.target</filename>.</para></listitem> |
| 102 |
</itemizedlist> |
| 103 |
</refsect2> |
| 104 |
</refsect1> |
| 105 |
|
| 106 |
<refsect1> |
| 107 |
<title><filename>fstab</filename></title> |
| 108 |
|
| 109 |
<para>Swap units may either be configured via unit files, or via |
| 110 |
<filename>/etc/fstab</filename> (see |
| 111 |
<citerefentry project='man-pages'><refentrytitle>fstab</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 112 |
for details). Swaps listed in <filename>/etc/fstab</filename> will |
| 113 |
be converted into native units dynamically at boot and when the |
| 114 |
configuration of the system manager is reloaded. See |
| 115 |
<citerefentry><refentrytitle>systemd-fstab-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 116 |
for details about the conversion.</para> |
| 117 |
|
| 118 |
<para>If a swap device or file is configured in both |
| 119 |
<filename>/etc/fstab</filename> and a unit file, the configuration |
| 120 |
in the latter takes precedence.</para> |
| 121 |
|
| 122 |
<para>When reading <filename>/etc/fstab</filename>, a few special |
| 123 |
options are understood by systemd which influence how dependencies |
| 124 |
are created for swap units.</para> |
| 125 |
|
| 126 |
<variablelist class='fstab-options'> |
| 127 |
<varlistentry> |
| 128 |
<term><option>noauto</option></term> |
| 129 |
<term><option>auto</option></term> |
| 130 |
|
| 131 |
<listitem><para>With <option>noauto</option>, the swap unit |
| 132 |
will not be added as a dependency for |
| 133 |
<filename>swap.target</filename> (or <filename>remote-fs.target</filename> for network swap devices, |
| 134 |
see <option>_netdev</option> below). This means that it will not |
| 135 |
be activated automatically during boot, unless it is pulled in |
| 136 |
by some other unit. The <option>auto</option> option has the |
| 137 |
opposite meaning and is the default.</para> |
| 138 |
|
| 139 |
<xi:include href="version-info.xml" xpointer="v218"/> |
| 140 |
</listitem> |
| 141 |
</varlistentry> |
| 142 |
|
| 143 |
<varlistentry> |
| 144 |
<term><option>nofail</option></term> |
| 145 |
|
| 146 |
<listitem><para>With <option>nofail</option>, the swap unit |
| 147 |
will be only wanted, not required by |
| 148 |
<filename>swap.target</filename> (or <filename>remote-fs.target</filename> for network swap |
| 149 |
devices). This means that the boot will continue even if this swap device is not activated |
| 150 |
successfully.</para> |
| 151 |
|
| 152 |
<xi:include href="version-info.xml" xpointer="v218"/> |
| 153 |
</listitem> |
| 154 |
</varlistentry> |
| 155 |
|
| 156 |
<xi:include href="systemd.mount.xml" xpointer="device-timeout" /> |
| 157 |
|
| 158 |
<varlistentry> |
| 159 |
<term><option>x-systemd.makefs</option></term> |
| 160 |
|
| 161 |
<listitem><para>The swap structure will be initialized on the device. If the device is not |
| 162 |
"empty", i.e. it contains any signature, the operation will be skipped. It is hence expected |
| 163 |
that this option remains set even after the device has been initialized.</para> |
| 164 |
|
| 165 |
<para>Note that this option can only be used in <filename>/etc/fstab</filename>, and will be |
| 166 |
ignored when part of the <varname>Options=</varname> setting in a unit file.</para> |
| 167 |
|
| 168 |
<para>See |
| 169 |
<citerefentry><refentrytitle>[email protected]</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 170 |
and the discussion of |
| 171 |
<citerefentry project='man-pages'><refentrytitle>wipefs</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 172 |
in <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 173 |
</para> |
| 174 |
|
| 175 |
<xi:include href="version-info.xml" xpointer="v240"/></listitem> |
| 176 |
</varlistentry> |
| 177 |
|
| 178 |
<varlistentry> |
| 179 |
<term><option>_netdev</option></term> |
| 180 |
|
| 181 |
<listitem><para>Marks this swap device as requiring network access. This is useful for swap on |
| 182 |
network block devices (e.g. iSCSI).</para> |
| 183 |
|
| 184 |
<para>Network swap units are ordered between <filename>remote-fs-pre.target</filename> and |
| 185 |
<filename>remote-fs.target</filename>, instead of being ordered before |
| 186 |
<filename>swap.target</filename>. They also pull in <filename>network-online.target</filename> and |
| 187 |
are ordered after it and <filename>network.target</filename>.</para> |
| 188 |
|
| 189 |
<xi:include href="version-info.xml" xpointer="v261"/> |
| 190 |
</listitem> |
| 191 |
</varlistentry> |
| 192 |
</variablelist> |
| 193 |
</refsect1> |
| 194 |
|
| 195 |
<refsect1> |
| 196 |
<title>Options</title> |
| 197 |
|
| 198 |
<para>Swap unit files may include [Unit] and [Install] sections, which are described in |
| 199 |
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 200 |
</para> |
| 201 |
|
| 202 |
<para>Swap unit files must include a [Swap] section, which carries |
| 203 |
information about the swap device it supervises. A number of |
| 204 |
options that may be used in this section are shared with other |
| 205 |
unit types. These options are documented in |
| 206 |
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
| 207 |
<citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry> and |
| 208 |
<citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 209 |
The options specific to the [Swap] section of swap units are the |
| 210 |
following:</para> |
| 211 |
|
| 212 |
<variablelist class='unit-directives'> |
| 213 |
|
| 214 |
<varlistentry> |
| 215 |
<term><varname>What=</varname></term> |
| 216 |
<listitem><para>Takes an absolute path or a fstab-style identifier of a device node or file to use |
| 217 |
for paging. See <citerefentry |
| 218 |
project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry> for |
| 219 |
details. If this refers to a device node, a dependency on the respective device unit is automatically |
| 220 |
created. (See |
| 221 |
<citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 222 |
for more information.) If this refers to a file, a dependency on the respective mount unit is |
| 223 |
automatically created. (See |
| 224 |
<citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry> for |
| 225 |
more information.) This option is mandatory. Note that the usual specifier expansion is applied to |
| 226 |
this setting, literal percent characters should hence be written as |
| 227 |
<literal class='specifiers'>%%</literal>.</para></listitem> |
| 228 |
</varlistentry> |
| 229 |
|
| 230 |
<varlistentry> |
| 231 |
<term><varname>Priority=</varname></term> |
| 232 |
|
| 233 |
<listitem><para>Swap priority to use when activating the swap |
| 234 |
device or file. This takes an integer. This setting is |
| 235 |
optional and ignored when the priority is set by <option>pri=</option> in the |
| 236 |
<varname>Options=</varname> key.</para></listitem> |
| 237 |
</varlistentry> |
| 238 |
|
| 239 |
<varlistentry> |
| 240 |
<term><varname>Options=</varname></term> |
| 241 |
|
| 242 |
<listitem><para>May contain an option string for the swap device. This may be used for controlling discard |
| 243 |
options among other functionality, if the swap backing device supports the discard or trim operation. (See |
| 244 |
<citerefentry project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 245 |
for more information.) Note that the usual specifier expansion is applied to this setting, literal percent |
| 246 |
characters should hence be written as <literal>%%</literal>.</para> |
| 247 |
|
| 248 |
<xi:include href="version-info.xml" xpointer="v217"/></listitem> |
| 249 |
</varlistentry> |
| 250 |
|
| 251 |
<varlistentry> |
| 252 |
<term><varname>TimeoutSec=</varname></term> |
| 253 |
<listitem><para>Configures the time to wait for the swapon |
| 254 |
command to finish. If a command does not exit within the |
| 255 |
configured time, the swap will be considered failed and be |
| 256 |
shut down again. All commands still running will be terminated |
| 257 |
forcibly via <constant>SIGTERM</constant>, and after another |
| 258 |
delay of this time with <constant>SIGKILL</constant>. (See |
| 259 |
<option>KillMode=</option> in |
| 260 |
<citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>.) |
| 261 |
Takes a unit-less value in seconds, or a time span value such |
| 262 |
as "5min 20s". Pass <literal>0</literal> to disable the |
| 263 |
timeout logic. Defaults to |
| 264 |
<varname>DefaultTimeoutStartSec=</varname> from the manager |
| 265 |
configuration file (see |
| 266 |
<citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>). |
| 267 |
</para></listitem> |
| 268 |
</varlistentry> |
| 269 |
</variablelist> |
| 270 |
|
| 271 |
<xi:include href="systemd.service.xml" xpointer="shared-unit-options" /> |
| 272 |
</refsect1> |
| 273 |
|
| 274 |
<refsect1> |
| 275 |
<title>See Also</title> |
| 276 |
<para><simplelist type="inline"> |
| 277 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 278 |
<member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 279 |
<member><citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 280 |
<member><citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 281 |
<member><citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 282 |
<member><citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 283 |
<member><citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 284 |
<member><citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 285 |
<member><citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 286 |
<member><citerefentry project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 287 |
<member><citerefentry><refentrytitle>systemd-fstab-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 288 |
<member><citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry></member> |
| 289 |
</simplelist></para> |
| 290 |
</refsect1> |
| 291 |
|
| 292 |
</refentry> |