SWAPON(8)
โจ SWAPON(8) โจ
okay bestie, we're in the System Administration chapter of the manual, and today's main characters are swapon and swapoff ๐
๐ธ NAME ๐ธ
swapon, swapoff โ turn devices and files on/off for paging and swapping ๐ฆ
๐ SYNOPSIS ๐
swapon [options] [specialfile...]
swapoff [-va] [specialfile...]
๐ DESCRIPTION ๐
swapon is the vibe-setter: you use it to name the devices where paging and swapping are gonna happen. periodt.
The device or file you're working with is the specialfile parameter. It can also show up as -L label or -U uuid to point at a device by its label or its uuid. iykyk ๐ซ
Calls to swapon normally happen inside your system boot scripts, making every swap device available โ that way the paging and swapping activity gets interleaved across several devices and files. main character energy fr fr ๐ฅ
swapoff does the opposite, obviously: it disables swapping on the devices and files you name. And when you pass the -a flag, swapping gets disabled on all known swap devices and files (as found in /proc/swaps or /etc/fstab). no cap ๐
๐ซถ OPTIONS ๐ซถ
-a,--allโ every device marked as"swap"in/etc/fstabgets made available, except the ones with the"noauto"option. Devices that are already being used as swap are silently skipped (no drama, they just get skipped). Peep the FSTAB CONFIGURATION section below for the deets ๐-T,--fstabpath โ points at an alternative fstab file, for compatibility withmount(8). If path is a directory, the files inside get sorted bystrverscmp(3); files that start with"."or that don't have an.fstabextension are ignored. You can specify this option more than once. It's mostly designed for initramfs or chroot scripts, where you've got extra configuration beyond the standard system config ๐-d,--discard[=policy]โ enables swap discards, but only if the swap backing device actually supports the discard or trim operation. This may improve performance on some Solid State Devices, but ngl, often it does not ๐ 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 become available for reuse.
If you don't select a policy, the default behavior is to enable both discard types. The /etc/fstab mount options discard, discard=once, or discard=pages may also be used to enable discard flags โจ
-e,--ifexistsโ silently skips devices that don't exist. The/etc/fstabmount optionnofailmay also be used to skip a non-existing device ๐-f,--fixpgszโ reinitializes (execsmkswap) the swap space if its page size doesn't match that of the current running kernel. Heads up:mkswap(8)initializes the whole device and does not check for bad blocks. you've been warned ๐ญ-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. Like, 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 giving final boss ๐ง
-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 ๐ซ-s,--summaryโ display swap usage summary by device. Equivalent tocat /proc/swaps. โ ๏ธ This output format is DEPRECATED in favour of--show, which gives you better control over the output data.--show[=column...]โ display a definable table of swap areas. See the--helpoutput for a list of available columns ๐ฅ--output-allโ output all available columns. all of them. every single one ๐--annotate[=when]โ adds an annotation to each column header name. Terminals that support this feature can show that annotation as a tooltip. The optional when argument can bealways,never, orauto. If the argument is omitted, it defaults toauto, which means annotations only get used when the output goes to a terminal โจ--noheadingsโ do not print headings when displaying--showoutput ๐--rawโ display--showoutput without aligning table columns ๐--bytesโ display swap size in bytes in--showoutput instead of in user-friendly units ๐ธ-Uuuid โ use the partition that has the specified uuid. ๐ฆ-v,--verboseโ be verbose. spill the tea โ-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? irrelevant, bye ๐
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=. so many ways to identify a device, iconic honestly ๐
๐ The second field (target)
Unused by swapon. The recommended convention is to use "none". it's just there for the vibes ๐
โจ The third field (type)
Requires "swap" as the filesystem type. non-negotiable ๐
๐ฆ The fourth field (options)
It's formatted as a comma-separated list of options. All unknown options are silently ignored. 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 this 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. The recommended convention is to keep it empty. ๐ซถ
๐ธ The sixth field
Unused by swapon. 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 error ๐32โ allswapofffailed on--all64โ someswapoffsucceeded on--all
The command swapoff --all returns 0 (all succeeded), 32 (all failed), or 64 (some failed, some succeeded).
- The old versions before v2.36 have no documented exit status.
0means 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. ๐ฌ
Commands like cp(1) or truncate(1) create files with holes. These files will be rejected by swapon.
Preallocated files created by fallocate(1) may be interpreted as files with holes too, depending on 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. that's the safe route bestie, trust ๐ซถ
๐ Btrfs
Swap files on Btrfs are supported since Linux 5.0, on files with the 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. โจ
๐ญ 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, thank u swapon ๐
๐ฐ๏ธ HISTORY ๐ฐ๏ธ
The swapon command appeared in 4.0BSD. an absolute legend fr fr ๐
๐ 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>. please actually report them, we wanna know ๐ซถ
๐ 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/>. ๐ฆ
and that's the whole page bestie!! this one came from util-linux 2.42.4, dated 2026-09-21 โ so if ur reading this way later, maybe go vibe check for a newer one ๐โจ
๐ฆ 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