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/fstabgets 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,--fstabpath โ specifies an alternative fstab file, for compatibility withmount(8). if path is a directory, the files inside get sorted bystrverscmp(3); files starting with"."or without an.fstabextension 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 atswapon; 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/fstabmount optionsdiscard,discard=once, ordiscard=pagesmay also be used to enable discard flags. choose your fighter ๐
-e,--ifexistsโ silently skips devices that don't exist. the/etc/fstabmount optionnofailmay also be used to skip a non-existing device. no missing-device meltdowns here ๐-f,--fixpgszโ reinitializes (execmkswap) 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 ๐ญ-Llabel โ use the partition that has the specified label. (for this, access to/proc/partitionsis needed.)-o,--optionsopts โ 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,--prioritypriority โ specify the priority of the swap device. priority is a value between0and32767. higher numbers indicate higher priority. seeswapon(2)for a full description of swap priorities. addpri=valueto the option field of/etc/fstabfor use withswapon -a. when no priority is defined, the Linux kernel defaults to negative numbers. lowkey spicy ๐ถ๏ธ-s,--summaryโ displays swap usage summary by device. equivalent tocat /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--helpoutput 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 bealways,never, orauto. if the argument is omitted, it defaults toauto, 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--showoutput.--rawโ display--showoutput without aligning table columns. chaotic but honest.--bytesโ display swap size in bytes in--showoutput instead of in user-friendly units. for the number girlies ๐ข-Uuuid โ 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 whenswapon --allis given.nofailโ do not report errors for this device if it does not exist.discard[=policy]โ enable swap discard. the supported settings arediscard,discard=once, ordiscard=pages. for more details, see the--discardcommand line option.pri=priorityโ specify the priority of the swap device. for more details, see the--prioritycommand 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 reason8โ non-swapoff(2)syscall system error (out of memory, ...)16โ usage or syntax error32โ all swapoff failed on--all64โ 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