1SWAPON(8)                    System Administration                   SWAPON(8)
2
3
4

NAME

6       swapon, swapoff - enable/disable devices and files for paging and
7       swapping
8

SYNOPSIS

10       swapon [options] [specialfile...]
11
12       swapoff [-va] [specialfile...]
13

DESCRIPTION

15       swapon is used to specify devices on which paging and swapping are to
16       take place.
17
18       The device or file used is given by the specialfile parameter. It may
19       be of the form -L label or -U uuid to indicate a device by label or
20       uuid.
21
22       Calls to swapon normally occur in the system boot scripts making all
23       swap devices available, so that the paging and swapping activity is
24       interleaved across several devices and files.
25
26       swapoff disables swapping on the specified devices and files. When the
27       -a flag is given, swapping is disabled on all known swap devices and
28       files (as found in /proc/swaps or /etc/fstab).
29

OPTIONS

31       -a, --all
32           All devices marked as "swap" in /etc/fstab are made available,
33           except for those with the "noauto" option. Devices that are already
34           being used as swap are silently skipped.
35
36       -T, --fstab path
37           Specifies an alternative fstab file for compatibility with
38           mount(8). If path is a directory, then the files in the directory
39           are sorted by strverscmp(3); files that start with "." or without
40           an .fstab extension are ignored. The option can be specified more
41           than once. This option is mostly designed for initramfs or chroot
42           scripts where additional configuration is specified beyond standard
43           system configuration.
44
45       -d, --discard[=policy]
46           Enable swap discards, if the swap backing device supports the
47           discard or trim operation. This may improve performance on some
48           Solid State Devices, but often it does not. The option allows one
49           to select between two available swap discard policies:
50
51           --discard=once
52               to perform a single-time discard operation for the whole swap
53               area at swapon; or
54
55           --discard=pages
56               to asynchronously discard freed swap pages before they are
57               available for reuse.
58
59           If no policy is selected, the default behavior is to enable both
60           discard types. The /etc/fstab mount options discard, discard=once,
61           or discard=pages may also be used to enable discard flags.
62
63       -e, --ifexists
64           Silently skip devices that do not exist. The /etc/fstab mount
65           option nofail may also be used to skip non-existing device.
66
67       -f, --fixpgsz
68           Reinitialize (exec mkswap) the swap space if its page size does not
69           match that of the current running kernel. mkswap(8) initializes the
70           whole device and does not check for bad blocks.
71
72       -L label
73           Use the partition that has the specified label. (For this, access
74           to /proc/partitions is needed.)
75
76       -o, --options opts
77           Specify swap options by an fstab-compatible comma-separated string.
78           For example:
79
80           swapon -o pri=1,discard=pages,nofail /dev/sda2
81
82           The opts string is evaluated last and overrides all other command
83           line options.
84
85       -p, --priority priority
86           Specify the priority of the swap device. priority is a value
87           between -1 and 32767. Higher numbers indicate higher priority. See
88           swapon(2) for a full description of swap priorities. Add pri=value
89           to the option field of /etc/fstab for use with swapon -a. When no
90           priority is defined, it defaults to -1.
91
92       -s, --summary
93           Display swap usage summary by device. Equivalent to cat
94           /proc/swaps. This output format is DEPRECATED in favour of --show
95           that provides better control on output data.
96
97       --show[=column...]
98           Display a definable table of swap areas. See the --help output for
99           a list of available columns.
100
101       --output-all
102           Output all available columns.
103
104       --noheadings
105           Do not print headings when displaying --show output.
106
107       --raw
108           Display --show output without aligning table columns.
109
110       --bytes
111           Display swap size in bytes in --show output instead of in
112           user-friendly units.
113
114       -U uuid
115           Use the partition that has the specified uuid.
116
117       -v, --verbose
118           Be verbose.
119
120       -h, --help
121           Display help text and exit.
122
123       -V, --version
124           Print version and exit.
125

EXIT STATUS

127       swapoff has the following exit status values since v2.36:
128
129       0
130           success
131
132       2
133           system has insufficient memory to stop swapping (OOM)
134
135       4
136           swapoff(2) syscall failed for another reason
137
138       8
139           non-swapoff(2) syscall system error (out of memory, ...)
140
141       16
142           usage or syntax error
143
144       32
145           all swapoff failed on --all
146
147       64
148           some swapoff succeeded on --all
149
150       The command swapoff --all returns 0 (all succeeded), 32 (all failed),
151       or 64 (some failed, some succeeded).
152
153       + The old versions before v2.36 has no documented exit status, 0 means
154       success in all versions.
155

ENVIRONMENT

157       LIBMOUNT_DEBUG=all
158           enables libmount debug output.
159
160       LIBBLKID_DEBUG=all
161           enables libblkid debug output.
162

FILES

164       /dev/sd??
165           standard paging devices
166
167       /etc/fstab
168           ascii filesystem description table
169

NOTES

171   Files with holes
172       The swap file implementation in the kernel expects to be able to write
173       to the file directly, without the assistance of the filesystem. This is
174       a problem on files with holes or on copy-on-write files on filesystems
175       like Btrfs.
176
177       Commands like cp(1) or truncate(1) create files with holes. These files
178       will be rejected by swapon.
179
180       Preallocated files created by fallocate(1) may be interpreted as files
181       with holes too depending of the filesystem. Preallocated swap files are
182       supported on XFS since Linux 4.18.
183
184       The most portable solution to create a swap file is to use dd(1) and
185       /dev/zero.
186
187   Btrfs
188       Swap files on Btrfs are supported since Linux 5.0 on files with nocow
189       attribute. See the btrfs(5) manual page for more details.
190
191   NFS
192       Swap over NFS may not work.
193
194   Suspend
195       swapon automatically detects and rewrites a swap space signature with
196       old software suspend data (e.g., S1SUSPEND, S2SUSPEND, ...). The
197       problem is that if we don’t do it, then we get data corruption the next
198       time an attempt at unsuspending is made.
199

HISTORY

201       The swapon command appeared in 4.0BSD.
202

SEE ALSO

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

REPORTING BUGS

208       For bug reports, use the issue tracker at
209       https://github.com/util-linux/util-linux/issues.
210

AVAILABILITY

212       The swapon command is part of the util-linux package which can be
213       downloaded from Linux Kernel Archive
214       <https://www.kernel.org/pub/linux/utils/util-linux/>.
215
216
217
218util-linux 2.39.2                 2023-08-17                         SWAPON(8)
Impressum