summaryrefslogtreecommitdiffstats
path: root/sys-utils/swapon.8
blob: b6b6797a449851bdf7ca815e4733fe1728bdbcf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
'\" t
.\"     Title: swapon
.\"    Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
.\"      Date: 2024-05-01
.\"    Manual: System Administration
.\"    Source: util-linux 2.40.1
.\"  Language: English
.\"
.TH "SWAPON" "8" "2024-05-01" "util\-linux 2.40.1" "System Administration"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.ss \n[.ss] 0
.nh
.ad l
.de URL
\fI\\$2\fP <\\$1>\\$3
..
.als MTO URL
.if \n[.g] \{\
.  mso www.tmac
.  am URL
.    ad l
.  .
.  am MTO
.    ad l
.  .
.  LINKSTYLE blue R < >
.\}
.SH "NAME"
swapon, swapoff \- enable/disable devices and files for paging and swapping
.SH "SYNOPSIS"
.sp
\fBswapon\fP [options] [\fIspecialfile\fP...]
.sp
\fBswapoff\fP [\fB\-va\fP] [\fIspecialfile\fP...]
.SH "DESCRIPTION"
.sp
\fBswapon\fP is used to specify devices on which paging and swapping are to take place.
.sp
The device or file used is given by the \fIspecialfile\fP parameter. It may be of the form \fB\-L\fP \fIlabel\fP or \fB\-U\fP \fIuuid\fP to indicate a device by label or uuid.
.sp
Calls to \fBswapon\fP normally occur in the system boot scripts making all swap devices available, so that the paging and swapping activity is interleaved across several devices and files.
.sp
\fBswapoff\fP disables swapping on the specified devices and files. When the \fB\-a\fP flag is given, swapping is disabled on all known swap devices and files (as found in \fI/proc/swaps\fP or \fI/etc/fstab\fP).
.SH "OPTIONS"
.sp
\fB\-a\fP, \fB\-\-all\fP
.RS 4
All devices marked as "swap" in \fI/etc/fstab\fP are made available, except for those with the "noauto" option. Devices that are already being used as swap are silently skipped.
.RE
.sp
\fB\-T\fP, \fB\-\-fstab\fP \fIpath\fP
.RS 4
Specifies an alternative fstab file for compatibility with \fBmount\fP(8). If \fIpath\fP is a directory, then the files in the directory are sorted by \fBstrverscmp\fP(3); files that start with "." or without an .fstab extension are ignored. The option can be specified more than once. This option is mostly designed for initramfs or chroot scripts where additional configuration is specified beyond standard system configuration.
.RE
.sp
\fB\-d\fP, \fB\-\-discard\fP[\fB=\fP\fIpolicy\fP]
.RS 4
Enable 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. The option allows one to select between two available swap discard policies:
.sp
\fB\-\-discard=once\fP
.RS 4
to perform a single\-time discard operation for the whole swap area at swapon; or
.RE
.sp
\fB\-\-discard=pages\fP
.RS 4
to asynchronously discard freed swap pages before they are available for reuse.
.RE
.sp
If no policy is selected, the default behavior is to enable both discard types. The \fI/etc/fstab\fP mount options \fBdiscard\fP, \fBdiscard=once\fP, or \fBdiscard=pages\fP may also be used to enable discard flags.
.RE
.sp
\fB\-e\fP, \fB\-\-ifexists\fP
.RS 4
Silently skip devices that do not exist. The \fI/etc/fstab\fP mount option \fBnofail\fP may also be used to skip non\-existing device.
.RE
.sp
\fB\-f\fP, \fB\-\-fixpgsz\fP
.RS 4
Reinitialize (exec mkswap) the swap space if its page size does not match that of the current running kernel. \fBmkswap\fP(8) initializes the whole device and does not check for bad blocks.
.RE
.sp
\fB\-L\fP \fIlabel\fP
.RS 4
Use the partition that has the specified \fIlabel\fP. (For this, access to \fI/proc/partitions\fP is needed.)
.RE
.sp
\fB\-o\fP, \fB\-\-options\fP \fIopts\fP
.RS 4
Specify swap options by an \fIfstab\fP\-compatible comma\-separated string. For example:
.sp
\fBswapon \-o pri=1,discard=pages,nofail /dev/sda2\fP
.sp
The \fIopts\fP string is evaluated last and overrides all other command line options.
.RE
.sp
\fB\-p\fP, \fB\-\-priority\fP \fIpriority\fP
.RS 4
Specify the priority of the swap device. \fIpriority\fP is a value between 0 and 32767. Higher numbers indicate higher priority. See \fBswapon\fP(2) for a full description of swap priorities. Add \fBpri=\fP\fIvalue\fP to the option field of \fI/etc/fstab\fP for use with \fBswapon \-a\fP. When no priority is defined, Linux kernel defaults to negative numbers.
.RE
.sp
\fB\-s\fP, \fB\-\-summary\fP
.RS 4
Display swap usage summary by device. Equivalent to \fBcat /proc/swaps\fP. This output format is DEPRECATED in favour of \fB\-\-show\fP that provides better control on output data.
.RE
.sp
\fB\-\-show\fP[\fB=\fP\fIcolumn\fP...]
.RS 4
Display a definable table of swap areas. See the \fB\-\-help\fP output for a list of available columns.
.RE
.sp
\fB\-\-output\-all\fP
.RS 4
Output all available columns.
.RE
.sp
\fB\-\-noheadings\fP
.RS 4
Do not print headings when displaying \fB\-\-show\fP output.
.RE
.sp
\fB\-\-raw\fP
.RS 4
Display \fB\-\-show\fP output without aligning table columns.
.RE
.sp
\fB\-\-bytes\fP
.RS 4
Display swap size in bytes in \fB\-\-show\fP output instead of in user\-friendly units.
.RE
.sp
\fB\-U\fP \fIuuid\fP
.RS 4
Use the partition that has the specified \fIuuid\fP.
.RE
.sp
\fB\-v\fP, \fB\-\-verbose\fP
.RS 4
Be verbose.
.RE
.sp
\fB\-h\fP, \fB\-\-help\fP
.RS 4
Display help text and exit.
.RE
.sp
\fB\-V\fP, \fB\-\-version\fP
.RS 4
Print version and exit.
.RE
.SH "EXIT STATUS"
.sp
\fBswapoff\fP has the following exit status values since v2.36:
.sp
\fB0\fP
.RS 4
success
.RE
.sp
\fB2\fP
.RS 4
system has insufficient memory to stop swapping (OOM)
.RE
.sp
\fB4\fP
.RS 4
\fBswapoff\fP(2) syscall failed for another reason
.RE
.sp
\fB8\fP
.RS 4
non\-\fBswapoff\fP(2) syscall system error (out of memory, ...)
.RE
.sp
\fB16\fP
.RS 4
usage or syntax error
.RE
.sp
\fB32\fP
.RS 4
all swapoff failed on \fB\-\-all\fP
.RE
.sp
\fB64\fP
.RS 4
some swapoff succeeded on \fB\-\-all\fP
.RE
.sp
The command \fBswapoff \-\-all\fP returns 0 (all succeeded), 32 (all failed), or 64 (some failed, some succeeded).
.sp
+
The old versions before v2.36 has no documented exit status, 0 means success in all versions.
.SH "ENVIRONMENT"
.sp
\fBLIBMOUNT_DEBUG\fP=all
.RS 4
enables \fBlibmount\fP debug output.
.RE
.sp
\fBLIBBLKID_DEBUG\fP=all
.RS 4
enables \fBlibblkid\fP debug output.
.RE
.SH "FILES"
.sp
\fI/dev/sd??\fP
.RS 4
standard paging devices
.RE
.sp
\fI/etc/fstab\fP
.RS 4
ascii filesystem description table
.RE
.SH "NOTES"
.SS "Files with holes"
.sp
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.
.sp
Commands like \fBcp\fP(1) or \fBtruncate\fP(1) create files with holes. These files will be rejected by \fBswapon\fP.
.sp
Preallocated files created by \fBfallocate\fP(1) may be interpreted as files with holes too depending of the filesystem. Preallocated swap files are supported on XFS since Linux 4.18.
.sp
The most portable solution to create a swap file is to use \fBdd\fP(1) and \fI/dev/zero\fP.
.SS "Btrfs"
.sp
Swap files on Btrfs are supported since Linux 5.0 on files with \fBnocow\fP attribute. See the \fBbtrfs\fP(5) manual page for more details.
.SS "NFS"
.sp
Swap over \fBNFS\fP may not work.
.SS "Suspend"
.sp
\fBswapon\fP automatically detects and rewrites a swap space signature with old software suspend data (e.g., \fBS1SUSPEND\fP, \fBS2SUSPEND\fP, ...). The problem is that if we don\(cqt do it, then we get data corruption the next time an attempt at unsuspending is made.
.SH "HISTORY"
.sp
The \fBswapon\fP command appeared in 4.0BSD.
.SH "SEE ALSO"
.sp
\fBswapoff\fP(2),
\fBswapon\fP(2),
\fBfstab\fP(5),
\fBinit\fP(8),
\fBfallocate\fP(1),
\fBmkswap\fP(8),
\fBmount\fP(8),
\fBrc\fP(8)
.SH "REPORTING BUGS"
.sp
For bug reports, use the issue tracker at \c
.URL "https://github.com/util\-linux/util\-linux/issues" "" "."
.SH "AVAILABILITY"
.sp
The \fBswapon\fP command is part of the util\-linux package which can be downloaded from \c
.URL "https://www.kernel.org/pub/linux/utils/util\-linux/" "Linux Kernel Archive" "."