1SWAPON(8) System Administration SWAPON(8)
2
3
4
6 swapon, swapoff - enable/disable devices and files for paging and
7 swapping
8
10 swapon [options] [specialfile...]
11
12 swapoff [-va] [specialfile...]
13
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
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 -d, --discard[=policy]
37 Enable swap discards, if the swap backing device supports the
38 discard or trim operation. This may improve performance on some
39 Solid State Devices, but often it does not. The option allows one
40 to select between two available swap discard policies:
41
42 --discard=once
43 to perform a single-time discard operation for the whole swap
44 area at swapon; or
45
46 --discard=pages
47 to asynchronously discard freed swap pages before they are
48 available for reuse.
49
50 If no policy is selected, the default behavior is to enable both
51 discard types. The /etc/fstab mount options discard, discard=once,
52 or discard=pages may also be used to enable discard flags.
53
54 -e, --ifexists
55 Silently skip devices that do not exist. The /etc/fstab mount
56 option nofail may also be used to skip non-existing device.
57
58 -f, --fixpgsz
59 Reinitialize (exec mkswap) the swap space if its page size does not
60 match that of the current running kernel. mkswap(8) initializes the
61 whole device and does not check for bad blocks.
62
63 -h, --help
64 Display help text and exit.
65
66 -L label
67 Use the partition that has the specified label. (For this, access
68 to /proc/partitions is needed.)
69
70 -o, --options opts
71 Specify swap options by an fstab-compatible comma-separated string.
72 For example:
73
74 swapon -o pri=1,discard=pages,nofail /dev/sda2
75
76 The opts string is evaluated last and overrides all other command
77 line options.
78
79 -p, --priority priority
80 Specify the priority of the swap device. priority is a value
81 between -1 and 32767. Higher numbers indicate higher priority. See
82 swapon(2) for a full description of swap priorities. Add pri=value
83 to the option field of /etc/fstab for use with swapon -a. When no
84 priority is defined, it defaults to -1.
85
86 -s, --summary
87 Display swap usage summary by device. Equivalent to cat
88 /proc/swaps. This output format is DEPRECATED in favour of --show
89 that provides better control on output data.
90
91 --show[=column...]
92 Display a definable table of swap areas. See the --help output for
93 a list of available columns.
94
95 --output-all
96 Output all available columns.
97
98 --noheadings
99 Do not print headings when displaying --show output.
100
101 --raw
102 Display --show output without aligning table columns.
103
104 --bytes
105 Display swap size in bytes in --show output instead of in
106 user-friendly units.
107
108 -U uuid
109 Use the partition that has the specified uuid.
110
111 -v, --verbose
112 Be verbose.
113
114 -V, --version
115 Display version information and exit.
116
118 swapoff has the following exit status values since v2.36:
119
120 0
121 success
122
123 2
124 system has insufficient memory to stop swapping (OOM)
125
126 4
127 swapoff syscall failed for another reason
128
129 8
130 non-swapoff syscall system error (out of memory, ...)
131
132 16
133 usage or syntax error
134
135 32
136 all swapoff failed on --all
137
138 64
139 some swapoff succeeded on --all
140
141 The command swapoff --all returns 0 (all succeeded), 32 (all failed),
142 or 64 (some failed, some succeeded).
143
144 + The old versions before v2.36 has no documented exit status, 0 means
145 success in all versions.
146
148 LIBMOUNT_DEBUG=all
149 enables libmount debug output.
150
151 LIBBLKID_DEBUG=all
152 enables libblkid debug output.
153
155 /dev/sd??
156 standard paging devices
157
158 /etc/fstab
159 ascii filesystem description table
160
162 Files with holes
163 The swap file implementation in the kernel expects to be able to write
164 to the file directly, without the assistance of the filesystem. This is
165 a problem on files with holes or on copy-on-write files on filesystems
166 like Btrfs.
167
168 Commands like cp(1) or truncate(1) create files with holes. These files
169 will be rejected by swapon.
170
171 Preallocated files created by fallocate(1) may be interpreted as files
172 with holes too depending of the filesystem. Preallocated swap files are
173 supported on XFS since Linux 4.18.
174
175 The most portable solution to create a swap file is to use dd(1) and
176 /dev/zero.
177
178 Btrfs
179 Swap files on Btrfs are supported since Linux 5.0 on files with nocow
180 attribute. See the btrfs(5) manual page for more details.
181
182 NFS
183 Swap over NFS may not work.
184
185 Suspend
186 swapon automatically detects and rewrites a swap space signature with
187 old software suspend data (e.g., S1SUSPEND, S2SUSPEND, ...). The
188 problem is that if we don’t do it, then we get data corruption the next
189 time an attempt at unsuspending is made.
190
192 The swapon command appeared in 4.0BSD.
193
195 swapoff(2), swapon(2), fstab(5), init(8), fallocate(1), mkswap(8),
196 mount(8), rc(8)
197
199 For bug reports, use the issue tracker at
200 https://github.com/karelzak/util-linux/issues.
201
203 The swapon command is part of the util-linux package which can be
204 downloaded from Linux Kernel Archive
205 <https://www.kernel.org/pub/linux/utils/util-linux/>.
206
207
208
209util-linux 2.37.2 2021-06-02 SWAPON(8)