SYSTEMD.SWAP(5)
okay so bestie</p>, you found your way to systemd.swap(5) โ that's the page in the systemd.swap manual, and it's all about swap units. Grab a boba, this one's actually kinda iconic. ๐ซถ
๐ธ NAME ๐ธ
systemd.swap โ swap unit configuration. That's it, that's the whole name. Short, sweet, main character energy. ๐
โจ SYNOPSIS โจ
swap.swap
yep that's the whole vibe check โ a file ending in .swap, periodt.
๐ฆ DESCRIPTION ๐ฆ
So a unit configuration file whose name ends in .swap is literally just a lil file that encodes info about a swap device or file for memory paging, and systemd is the one controlling and supervising it. It's giving "I watch your memory paging for you, no cap." ๐
This man page right here lists the config options that are specific to this unit type. If you want the common options that every unit configuration file gets, run don't walk to systemd.unit(5). Those common config items live in the generic [Unit] and [Install] sections. And the swap-specific ones? Those go in the [Swap] section. Iykyk. โจ
There's more stuff hiding in other pages too:
systemd.exec(5)โ defines the execution environment that theswapon(8)program is executed in. ๐โโ๏ธsystemd.kill(5)โ defines the way these processes are terminated. ๐systemd.resource-control(5)โ configures resource control settings for these processes of the unit. ๐๏ธ
Now, the naming rule, and bestie listen up because this one's strict: swap units must be named after the devices or files they control. Example, since examples are everything: the swap device /dev/sda5 must be configured in a unit file called dev-sda5.swap. That's just how it is. ๐
Wanna know about the whole escaping logic that converts a file system path into a unit name? systemd.unit(5), go off. But also note: swap units cannot be templated, and it's not possible to add multiple names to a swap unit by creating additional symlinks to it. Sorry babe, one name only. ๐ซ
And one more thing that's lowkey important: swap support on Linux is privileged. So swap units are only available in the system service manager (and root's user service manager) โ but not in an unprivileged user's service manager. Privilege check: failed. ๐ญ
๐ซ AUTOMATIC DEPENDENCIES ๐ซ
๐ฎ Implicit Dependencies
The following dependencies are implicitly added, like systemd is just doing it for you behind the scenes, no questions asked:
- All swap units automatically get the
Requires=andAfter=dependencies on the device units or the mount units of the files they are activated from. ๐ซถ
And also โ additional implicit dependencies may be added as a result of execution and resource control parameters, as documented in systemd.exec(5) and systemd.resource-control(5). Surprise dependencies, love that for us. โจ
๐ Default Dependencies
These get added unless DefaultDependencies=no is set:
- Local swap units automatically acquire a
Conflicts=and aBefore=dependency onumount.targetso that they are deactivated at shutdown, plus aBefore=swap.targetdependency. Gotta clean up before you leave the party. ๐งน - Network swap units (the ones with
_netdevin their options) automatically acquireAfter=dependencies onremote-fs-pre.targetandnetwork.target, plusAfter=andWants=dependencies onnetwork-online.target, and aBefore=dependency onremote-fs.targetinstead ofswap.target. Network girlies get a whole different social calendar. ๐
๐ FSTAB ๐
Okay so swap units can come to you in two flavors: via unit files, or via /etc/fstab (peep fstab(5) for the deets). Swaps listed in /etc/fstab get converted into native units dynamically at boot and also when the configuration of the system manager is reloaded. Wanna see the conversion magic? systemd-fstab-generator(8). ๐ฅ
And if a swap device or file is configured in both /etc/fstab and a unit file? The configuration in the latter takes precedence. Unit file wins, sorry not sorry. ๐
When reading /etc/fstab, there are a few special options that systemd understands, and they influence how dependencies get created for swap units. Let's go:
noauto,autoโ Withnoauto, the swap unit will not be added as a dependency forswap.target(orremote-fs.targetfor network swap devices, see_netdevbelow). Which means it will not be activated automatically during boot, unless it gets pulled in by some other unit. Theautooption is the opposite meaning and is the default. โจ Added in version 218.nofailโ Withnofail, the swap unit will be only wanted, not required, byswap.target(orremote-fs.targetfor network swap devices). Which means the boot will keep going even if this swap device doesn't activate successfully. Resilient queen behavior. ๐ Added in version 218.x-systemd.device-timeout=โ Configures how long systemd should wait for a device to show up before giving up on an entry from/etc/fstab. Specify a time in seconds, or explicitly append a unit such as"s","min","h","ms". โฐ Note: this option can only be used in/etc/fstab, and will be ignored when it's part of theOptions=setting in a unit file. Added in version 215.x-systemd.makefsโ The swap structure will be initialized on the device. If the device is not "empty", i.e. it contains any signature, the operation will be skipped. Which is why it's expected that this option remains set even after the device has been initialized. ๐ง Note: again, this option can only be used in/etc/fstab, and will be ignored when part of theOptions=setting in a unit file. Also go look atsystemd-mkswap@.service(8)and the discussion ofwipefs(8)insystemd.mount(5). Added in version 240._netdevโ Marks this swap device as requiring network access. Super useful for swap on network block devices (e.g. iSCSI). ๐ Network swap units are ordered betweenremote-fs-pre.targetandremote-fs.target, instead of being ordered beforeswap.target. They also pull innetwork-online.targetand are ordered after it andnetwork.target. Added in version 261.
๐ OPTIONS ๐
Swap unit files may include [Unit] and [Install] sections โ those are described over in systemd.unit(5). ๐
Swap unit files must include a [Swap] section, and that's the one carrying information about the swap device it supervises. A bunch of options you can use in this section are shared with other unit types โ those are documented in systemd.exec(5), systemd.kill(5) and systemd.resource-control(5). ๐
But the options that are specific to the [Swap] section of swap units? Those are these, bestie:
What=โ Takes an absolute path or a fstab-style identifier of a device node or file to use for paging. Seeswapon(8)for details. If this refers to a device node, a dependency on the respective device unit is automatically created (seesystemd.device(5)for more). If this refers to a file, a dependency on the respective mount unit is automatically created (seesystemd.mount(5)for more). This option is mandatory. And note that the usual specifier expansion is applied to this setting, so literal percent characters should hence be written as"%%". ๐ฏPriority=โ Swap priority to use when activating the swap device or file. Takes an integer. This setting is optional and gets ignored when the priority is set bypri=in theOptions=key. ๐ฅOptions=โ May contain an option string for the swap device. This may be used for controlling discard options among other functionality, if the swap backing device supports the discard or trim operation. (Seeswapon(8)for more information.) Note that the usual specifier expansion is applied to this setting, so literal percent characters should hence be written as"%%". โจ Added in version 217.TimeoutSec=โ Configures the time to wait for theswaponcommand to finish. If a command does not exit within the configured time, the swap will be considered failed and be shut down again. All commands still running will be terminated forcibly viaSIGTERM, and after another delay of this time withSIGKILL. (SeeKillMode=insystemd.kill(5).) ๐ญ Takes a unit-less value in seconds, or a time span value such as"5min 20s". Pass"0"to disable the timeout logic. Defaults toDefaultTimeoutStartSec=from the manager configuration file (seesystemd-system.conf(5)). โณ
And for even more settings, go check systemd.unit(5), systemd.exec(5), and systemd.kill(5). ๐ซถ
๐ SEE ALSO ๐
systemd(1), systemctl(1), systemd-system.conf(5), systemd.unit(5), systemd.exec(5), systemd.kill(5), systemd.resource-control(5), systemd.device(5), systemd.mount(5), swapon(8), systemd-fstab-generator(8), systemd.directives(7)
and that's the whole page, you ate it ๐ฝ๏ธโจ this little cutie came from systemd 262.1 and it's the SYSTEMD.SWAP(5) page, so go forth and swap responsibly, bestie ๐๐ธ๐ฆ
๐ฆ where this page comes from
- arch rolling: systemd 262.1-1 ยท LGPL-2.1-or-later AND CC0-1.0 AND GPL-2.0-or-later AND MIT-0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms