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 the swapon(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= and After= 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 a Before= dependency on umount.target so that they are deactivated at shutdown, plus a Before=swap.target dependency. Gotta clean up before you leave the party. ๐Ÿงน
  • Network swap units (the ones with _netdev in their options) automatically acquire After= dependencies on remote-fs-pre.target and network.target, plus After= and Wants= dependencies on network-online.target, and a Before= dependency on remote-fs.target instead of swap.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 โ€” With noauto, the swap unit will not be added as a dependency for swap.target (or remote-fs.target for network swap devices, see _netdev below). Which means it will not be activated automatically during boot, unless it gets pulled in by some other unit. The auto option is the opposite meaning and is the default. โœจ Added in version 218.
  • nofail โ€” With nofail, the swap unit will be only wanted, not required, by swap.target (or remote-fs.target for 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 the Options= 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 the Options= setting in a unit file. Also go look at systemd-mkswap@.service(8) and the discussion of wipefs(8) in systemd.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 between remote-fs-pre.target and remote-fs.target, instead of being ordered before swap.target. They also pull in network-online.target and are ordered after it and network.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. See swapon(8) for details. If this refers to a device node, a dependency on the respective device unit is automatically created (see systemd.device(5) for more). If this refers to a file, a dependency on the respective mount unit is automatically created (see systemd.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 by pri= in the Options= 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. (See swapon(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 the swapon command 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 via SIGTERM, and after another delay of this time with SIGKILL. (See KillMode= in systemd.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 to DefaultTimeoutStartSec= from the manager configuration file (see systemd-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