]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/swapon.8
Manual pages: order NOTES / HISTORY / BUGS / EXAMPLE consistently
[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 .B 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 .B \-\-discard=once
87 to perform a single-time discard operation for the whole swap area at swapon;
88 or
89 .B \-\-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 (8)
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 \-\-output\-all
164 Output all available columns.
165 .TP
166 .B \-\-noheadings
167 Do not print headings when displaying
168 .B \-\-show
169 output.
170 .TP
171 .B \-\-raw
172 Display
173 .B \-\-show
174 output without aligning table columns.
175 .TP
176 .B \-\-bytes
177 Display swap size in bytes in
178 .B \-\-show
179 output instead of in user-friendly units.
180 .TP
181 .BI \-U " uuid"
182 Use the partition that has the specified
183 .IR uuid .
184 .TP
185 .BR \-v , " \-\-verbose"
186 Be verbose.
187 .TP
188 .BR \-V , " \-\-version"
189 Display version information and exit.
190 .SH ENVIRONMENT
191 .IP LIBMOUNT_DEBUG=all
192 enables libmount debug output.
193 .IP LIBBLKID_DEBUG=all
194 enables libblkid debug output.
195
196 .SH FILES
197 .br
198 .I /dev/sd??
199 standard paging devices
200 .br
201 .I /etc/fstab
202 ascii filesystem description table
203 .SH NOTES
204 .SS Files with holes
205 The swap file implementation in the kernel expects to be able to write to the
206 file directly, without the assistance of the filesystem. This is a problem on
207 files with holes or on copy-on-write files on filesystems like Btrfs.
208 .sp
209 Commands like
210 .BR cp (1)
211 or
212 .BR truncate (1)
213 create files with holes. These files will be rejected by swapon.
214 .sp
215 Preallocated files created by
216 .BR fallocate (1)
217 may be interpreted as files with holes too depending of the filesystem.
218 Preallocated swap files are supported on XFS since Linux 4.18.
219 .sp
220 The most portable solution to create a swap file is to use
221 .BR dd (1)
222 and /dev/zero.
223 .SS Btrfs
224 Swap files on Btrfs are supported since Linux 5.0 on files with nocow attribute.
225 See the
226 .BR btrfs (5)
227 manual page for more details.
228 .SS NFS
229 Swap over \fBNFS\fR may not work.
230 .SS Suspend
231 .B swapon
232 automatically detects and rewrites a swap space signature with old software
233 suspend data (e.g., S1SUSPEND, S2SUSPEND, ...). The problem is that if we don't
234 do it, then we get data corruption the next time an attempt at unsuspending is
235 made.
236 .SH HISTORY
237 The
238 .B swapon
239 command appeared in 4.0BSD.
240 .SH SEE ALSO
241 .BR swapoff (2),
242 .BR swapon (2),
243 .BR fstab (5),
244 .BR init (8),
245 .BR fallocate (1),
246 .BR mkswap (8),
247 .BR mount (8),
248 .BR rc (8)
249 .SH AVAILABILITY
250 The swapon command is part of the util-linux package and is available from
251 https://www.kernel.org/pub/linux/utils/util-linux/.