SWAPON(8)

๐Ÿ’– SWAPON(8) โ€” the swap girlies' manual (System Administration) ๐Ÿ’–

okay bestie, welcome to swapon and swapoff, two icons from the util-linux world, section 8, system administration division. they're literally the reason your RAM gets to breathe. let's get into it ๐Ÿซถ


โœจ NAME โœจ

swapon, swapoff โ€” enable/disable devices and files for paging and swapping


๐ŸŒธ SYNOPSIS ๐ŸŒธ

swapon [options] [specialfile...]

swapoff [-va] [specialfile...]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so swapon is the one you call to specify which devices are gonna host your paging and swapping. it's giving "here's where the overflow goes, babe" ๐Ÿ’…

the device or file you're blessing is given by the specialfile parameter. and get this โ€” it can also be in the form -L label or -U uuid, which is how you point at a device by its label or its uuid. iconic, flexible, no notes.

calls to swapon normally happen inside the system boot scripts, where all your swap devices get made available โ€” so that paging and swapping activity gets interleaved across several devices and files. multitasking queen behavior fr fr โœจ

swapoff is the opposite vibe: it disables swapping on the devices and files you name. and when you hand it the -a flag, swapping gets disabled on all known swap devices and files (as found in /proc/swaps or /etc/fstab). bye bye swap ๐Ÿ‘‹


๐Ÿ’… OPTIONS ๐Ÿ’…

  • -a, --all โ€” every device marked as "swap" in /etc/fstab gets made available, EXCEPT the ones with the "noauto" option. devices already being used as swap are silently skipped (no drama, no errors). peep the FSTAB CONFIGURATION section below for the tea.
  • -T, --fstab path โ€” specifies an alternative fstab file, for compatibility with mount(8). if path is a directory, the files inside get sorted by strverscmp(3); files starting with "." or without an .fstab extension get ignored. you can pass this option more than once. it's mostly designed for initramfs or chroot scripts, where extra config lives beyond the standard system config. very niche, very valid.
  • -d, --discard[=policy] โ€” enables swap discards, IF the swap backing device supports the discard or trim operation. this may improve performance on some Solid State Devices, but often it does not (ngl, temper your expectations). the option lets you pick between two available swap discard policies:
    • --discard=once โ€” performs a single-time discard operation for the whole swap area at swapon; or
    • --discard=pages โ€” asynchronously discards freed swap pages before they're available for reuse.
    • if no policy is selected, the default behavior is to enable both discard types. and the /etc/fstab mount options discard, discard=once, or discard=pages may also be used to enable discard flags. choose your fighter ๐ŸŽ€
  • -e, --ifexists โ€” silently skips devices that don't exist. the /etc/fstab mount option nofail may also be used to skip a non-existing device. no missing-device meltdowns here ๐Ÿ’–
  • -f, --fixpgsz โ€” reinitializes (exec mkswap) the swap space if its page size doesn't match that of the current running kernel. heads up though: mkswap(8) initializes the whole device and does not check for bad blocks. so like, it's thorough but it's not doing a background check ๐Ÿ˜ญ
  • -L label โ€” use the partition that has the specified label. (for this, access to /proc/partitions is needed.)
  • -o, --options opts โ€” specify swap options with an fstab-compatible comma-separated string. for example:
swapon -o pri=1,discard=pages,nofail /dev/sda2

the opts string is evaluated last and overrides all other command line options. it's the final boss of your flags ๐Ÿ‘‘

  • -p, --priority priority โ€” specify the priority of the swap device. priority is a value between 0 and 32767. higher numbers indicate higher priority. see swapon(2) for a full description of swap priorities. add pri=value to the option field of /etc/fstab for use with swapon -a. when no priority is defined, the Linux kernel defaults to negative numbers. lowkey spicy ๐ŸŒถ๏ธ
  • -s, --summary โ€” displays swap usage summary by device. equivalent to cat /proc/swaps. > this output format is DEPRECATED in favour of --show, which provides better control on output data. so use --show, bestie, she's the upgrade.
  • --show[=column...] โ€” displays a definable table of swap areas. see the --help output for a list of available columns. customizable queen โœจ
  • --output-all โ€” outputs all available columns. everything, everywhere, all at once.
  • --annotate[=when] โ€” adds an annotation to each column header name. such an annotation can be shown as a tooltip by terminals that support this feature. the optional when argument can be always, never, or auto. if the argument is omitted, it defaults to auto, which means annotations will only be used when the output goes to a terminal. so smart, so context-aware ๐Ÿ’…
  • --noheadings โ€” do not print headings when displaying --show output.
  • --raw โ€” display --show output without aligning table columns. chaotic but honest.
  • --bytes โ€” display swap size in bytes in --show output instead of in user-friendly units. for the number girlies ๐Ÿ”ข
  • -U uuid โ€” use the partition that has the specified uuid.
  • -v, --verbose โ€” be verbose. tell me everything ๐Ÿ—ฃ๏ธ
  • -h, --help โ€” display help text and exit.
  • -V, --version โ€” display version and exit.

๐ŸŽ€ FSTAB CONFIGURATION ๐ŸŽ€

the command swapon --all reads configuration from /etc/fstab (or from a file specified by the --fstab command line option). only fstab entries with the filesystem type (3rd field) set to "swap" are relevant. everything else? not invited to the party.

the option --options accepts values in the same form as can be specified in the fourth field in fstab.

the first field (source) ๐Ÿ“

specify the swap source. if the source is a regular file, it's addressed by an absolute path.

if the swap is a block device, it can be addressed by device path, swap area tags LABEL= or UUID= (see mkswap(8) for more details), or by partition tags like PARTLABEL= or PARTUUID=.

the second field (target) ๐ŸŒธ

unused by swapon, and the recommended convention is to use "none".

the third field (type) ๐Ÿฆ‹

requires "swap" as the filesystem type. no substitutes, no swaps for the swap (pun intended).

the fourth field (options) ๐Ÿ’œ

it's formatted as a comma-separated list of options. all unknown options are silently ignored (she's unbothered). if options are unnecessary, the recommended convention is to use "defaults". the options specified in fstab extend or overwrite settings specified on the swapon command line.

supported swap options:

  • noauto โ€” ignore entry when swapon --all is given.
  • nofail โ€” do not report errors for this device if it does not exist.
  • discard[=policy] โ€” enable swap discard. the supported settings are discard, discard=once, or discard=pages. for more details, see the --discard command line option.
  • pri=priority โ€” specify the priority of the swap device. for more details, see the --priority command line option.

the fifth field ๐ŸŒˆ

unused by swapon, and the recommended convention is to keep it empty.

the sixth field โญ

unused by swapon, and the recommended convention is to keep it empty.


๐Ÿ”ฅ EXIT STATUS ๐Ÿ”ฅ

swapoff has the following exit status values since v2.36:

  • 0 โ€” success โœจ
  • 2 โ€” system has insufficient memory to stop swapping (OOM) ๐Ÿ˜ญ
  • 4 โ€” swapoff(2) syscall failed for another reason
  • 8 โ€” non-swapoff(2) syscall system error (out of memory, ...)
  • 16 โ€” usage or syntax error
  • 32 โ€” all swapoff failed on --all
  • 64 โ€” some swapoff succeeded on --all

the command swapoff --all returns 0 (all succeeded), 32 (all failed), or 64 (some failed, some succeeded). it's giving graded results ๐Ÿ“Š

+ the old versions before v2.36 has no documented exit status, 0 means success in all versions.

๐ŸŒŸ ENVIRONMENT ๐ŸŒŸ

  • LIBMOUNT_DEBUG=all โ€” enables libmount debug output.
  • LIBBLKID_DEBUG=all โ€” enables libblkid debug output.

๐Ÿงš FILES ๐Ÿงš

  • /dev/sd?? โ€” standard paging devices
  • /etc/fstab โ€” ascii filesystem description table

๐Ÿ’€ NOTES ๐Ÿ’€

files with holes ๐Ÿ•ณ๏ธ

the swap file implementation in the kernel expects to be able to write to the file directly, without the assistance of the filesystem. this is a problem on files with holes or on copy-on-write files on filesystems like Btrfs. like, she needs direct access, okay??

commands like cp(1) or truncate(1) create files with holes. these files will be rejected by swapon. not a vibe.

preallocated files created by fallocate(1) may be interpreted as files with holes too, depending of the filesystem. preallocated swap files are supported on XFS since Linux 4.18.

the most portable solution to create a swap file is to use dd(1) and /dev/zero. old reliable fr fr ๐Ÿ’–

Btrfs ๐ŸŒณ

swap files on Btrfs are supported since Linux 5.0 on files with nocow attribute. see the btrfs(5) manual page for more details.

since version 2.41, the command mkswap --file can create a new swap file with the nocow attribute. glow up โœจ

NFS ๐Ÿ“ก

swap over NFS may not work. that's it, that's the note. ๐Ÿ™ˆ

suspend ๐Ÿ˜ด

swapon automatically detects and rewrites a swap space signature with old software suspend data (e.g., S1SUSPEND, S2SUSPEND, ...). the problem is that if we don't do it, then we get data corruption the next time an attempt at unsuspending is made. so like, she's doing it for your own good, bestie ๐Ÿซถ


๐Ÿ‘‘ HISTORY ๐Ÿ‘‘

the swapon command appeared in 4.0BSD. vintage. classic. mother.


๐Ÿ’– SEE ALSO ๐Ÿ’–

swapoff(2), swapon(2), fstab(5), init(8), fallocate(1), mkswap(8), mount(8), rc(8)


๐Ÿ› REPORTING BUGS ๐Ÿ›

for bug reports, use the issue tracker <https://github.com/util-linux/util-linux/issues>. don't be shy, they wanna hear it.


๐ŸŒˆ AVAILABILITY ๐ŸŒˆ

the swapon command is part of the util-linux package which can be downloaded from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils/util-linux/>.


okay that's the whole page, you ate that ๐ŸŽ€ this was util-linux 2.42.4, dated 2026-09-21, and it's the SWAPON(8) manual โ€” go forth and swap responsibly, bestie ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from
  • arch rolling: util-linux 2.42.4-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause-UC AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND ISC AND LGPL-2.1-or-later AND LicenseRef-PublicDomain
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms