]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/swapon.8
Merge branch 'path-fixes' of https://github.com/rudimeier/util-linux
[thirdparty/util-linux.git] / sys-utils / swapon.8
1 .\" Copyright (c) 1980, 1991 Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\" @(#)swapon.8 6.3 (Berkeley) 3/16/91
33 .\"
34 .TH SWAPON 8 "October 2014" "util-linux" "System Administration"
35 .SH NAME
36 swapon, swapoff \- enable/disable devices and files for paging and swapping
37 .SH SYNOPSIS
38 .BR swapon
39 [options]
40 .RI [ specialfile ...]
41 .br
42 .B swapoff
43 .RB [ \-va ]
44 .RI [ specialfile ...]
45 .SH DESCRIPTION
46 .B swapon
47 is used to specify devices on which paging and swapping are to take place.
48
49 The device or file used is given by the
50 .I specialfile
51 parameter. It may be of the form
52 .BI \-L " label"
53 or
54 .BI \-U " uuid"
55 to indicate a device by label or uuid.
56
57 Calls to
58 .B swapon
59 normally occur in the system boot scripts making all swap devices available, so
60 that the paging and swapping activity is interleaved across several devices and
61 files.
62
63 .B swapoff
64 disables swapping on the specified devices and files.
65 When the
66 .B \-a
67 flag is given, swapping is disabled on all known swap devices and files
68 (as found in
69 .I /proc/swaps
70 or
71 .IR /etc/fstab ).
72
73 .SH OPTIONS
74 .TP
75 .BR \-a , " \-\-all"
76 All devices marked as ``swap'' in
77 .I /etc/fstab
78 are made available, except for those with the ``noauto'' option.
79 Devices that are already being used as swap are silently skipped.
80 .TP
81 .BR \-d , " \-\-discard" [ =\fIpolicy\fR]
82 Enable swap discards, if the swap backing device supports the discard or
83 trim operation. This may improve performance on some Solid State Devices,
84 but often it does not. The option allows one to select between two
85 available swap discard policies:
86 .BI \-\-discard=once
87 to perform a single-time discard operation for the whole swap area at swapon;
88 or
89 .BI \-\-discard=pages
90 to asynchronously discard freed swap pages before they are available for reuse.
91 If no policy is selected, the default behavior is to enable both discard types.
92 The
93 .I /etc/fstab
94 mount options
95 .BR discard ,
96 .BR discard=once ,
97 or
98 .B discard=pages
99 may also be used to enable discard flags.
100 .TP
101 .BR \-e , " \-\-ifexists"
102 Silently skip devices that do not exist.
103 The
104 .I /etc/fstab
105 mount option
106 .B nofail
107 may also be used to skip non-existing device.
108
109 .TP
110 .BR \-f , " \-\-fixpgsz"
111 Reinitialize (exec mkswap) the swap space if its page size does not
112 match that of the current running kernel.
113 .BR mkswap (2)
114 initializes the whole device and does not check for bad blocks.
115 .TP
116 .BR \-h , " \-\-help"
117 Display help text and exit.
118 .TP
119 .BI \-L " label"
120 Use the partition that has the specified
121 .IR label .
122 (For this, access to
123 .I /proc/partitions
124 is needed.)
125 .TP
126 .BR \-o , " \-\-options " \fIopts\fP
127 Specify swap options by an fstab-compatible comma-separated string.
128 For example:
129 .RS
130 .RS
131 .sp
132 .B "swapon -o pri=1,discard=pages,nofail /dev/sda2"
133 .sp
134 .RE
135 The \fIopts\fP string is evaluated last and overrides all other
136 command line options.
137 .RE
138 .TP
139 .BR \-p , " \-\-priority " \fIpriority\fP
140 Specify the priority of the swap device.
141 .I priority
142 is a value between \-1 and 32767. Higher numbers indicate
143 higher priority. See
144 .BR swapon (2)
145 for a full description of swap priorities. Add
146 .BI pri= value
147 to the option field of
148 .I /etc/fstab
149 for use with
150 .BR "swapon -a" .
151 When no priority is defined, it defaults to \-1.
152 .TP
153 .BR \-s , " \-\-summary"
154 Display swap usage summary by device. Equivalent to "cat /proc/swaps".
155 This output format is DEPRECATED in favour
156 of \fB\-\-show\fR that provides better control on output data.
157 .TP
158 .BR \-\-show [ =\fIcolumn\fR ...]
159 Display a definable table of swap areas. See the
160 .B \-\-help
161 output for a list of available columns.
162 .TP
163 .B \-\-noheadings
164 Do not print headings when displaying
165 .B \-\-show
166 output.
167 .TP
168 .B \-\-raw
169 Display
170 .B \-\-show
171 output without aligning table columns.
172 .TP
173 .B \-\-bytes
174 Display swap size in bytes in
175 .B \-\-show
176 output instead of in user-friendly units.
177 .TP
178 .BI \-U " uuid"
179 Use the partition that has the specified
180 .IR uuid .
181 .TP
182 .BR \-v , " \-\-verbose"
183 Be verbose.
184 .TP
185 .BR \-V , " \-\-version"
186 Display version information and exit.
187 .SH NOTES
188 You should not use \fBswapon\fR on a file with holes.
189 This can be seen in the system log as
190 .RS
191 .sp
192 .B "swapon: swapfile has holes."
193 .sp
194 .RE
195 The swap file implementation in the kernel expects to be able to write to the
196 file directly, without the assistance of the filesystem. This is a problem on
197 preallocated files (e.g.
198 .BR fallocate (1))
199 on filesystems like \fBXFS\fR or \fBext4\fR, and on copy-on-write
200 filesystems like \fBbtrfs\fR.
201 .PP
202 It is recommended to use
203 .BR dd (1)
204 and
205 .I /dev/zero
206 to avoid holes on XFS and ext4.
207 .PP
208 .B swapon
209 may not work correctly when using a swap file with some versions of
210 \fBbtrfs\fR. This is due to btrfs being a copy-on-write filesystem: the
211 file location may not be static and corruption can result. Btrfs actively
212 disallows the use of swap files on its filesystems by refusing to map the file.
213 .PP
214 One possible workaround is to map the swap
215 file to a loopback device. This will allow the filesystem to determine the
216 mapping properly but may come with a performance impact.
217 .PP
218 Swap over \fBNFS\fR may not work.
219 .PP
220 .B swapon
221 automatically detects and rewrites a swap space signature with old software
222 suspend data (e.g S1SUSPEND, S2SUSPEND, ...). The problem is that if we don't
223 do it, then we get data corruption the next time an attempt at unsuspending is
224 made.
225
226 .SH ENVIRONMENT
227 .IP LIBMOUNT_DEBUG=all
228 enables libmount debug output.
229 .IP LIBBLKID_DEBUG=all
230 enables libblkid debug output.
231
232 .SH SEE ALSO
233 .BR swapoff (2),
234 .BR swapon (2),
235 .BR fstab (5),
236 .BR init (8),
237 .BR mkswap (8),
238 .BR mount (8),
239 .BR rc (8)
240 .SH FILES
241 .br
242 .I /dev/sd??
243 standard paging devices
244 .br
245 .I /etc/fstab
246 ascii filesystem description table
247 .SH HISTORY
248 The
249 .B swapon
250 command appeared in 4.0BSD.
251 .SH AVAILABILITY
252 The swapon command is part of the util-linux package and is available from
253 https://www.kernel.org/pub/linux/utils/util-linux/.