]> git.ipfire.org Git - thirdparty/util-linux.git/blame - sys-utils/swapon.8
Manual pages: order NOTES / HISTORY / BUGS / EXAMPLE consistently
[thirdparty/util-linux.git] / sys-utils / swapon.8
CommitLineData
6dbe3af9
KZ
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.\"
b1301d78 34.TH SWAPON 8 "October 2014" "util-linux" "System Administration"
6dbe3af9
KZ
35.SH NAME
36swapon, swapoff \- enable/disable devices and files for paging and swapping
37.SH SYNOPSIS
0bb7e904 38.B swapon
1f94a78c
BS
39[options]
40.RI [ specialfile ...]
fd6b7a7f 41.br
1581e22c 42.B swapoff
7bed68bf 43.RB [ \-va ]
1f94a78c 44.RI [ specialfile ...]
6dbe3af9 45.SH DESCRIPTION
ce6479e2 46.B swapon
6dbe3af9 47is used to specify devices on which paging and swapping are to take place.
756bfd01
KZ
48
49The device or file used is given by the
50.I specialfile
1f94a78c 51parameter. It may be of the form
756bfd01
KZ
52.BI \-L " label"
53or
54.BI \-U " uuid"
55to indicate a device by label or uuid.
56
6dbe3af9
KZ
57Calls to
58.B swapon
1581e22c
KZ
59normally occur in the system boot scripts making all swap devices available, so
60that the paging and swapping activity is interleaved across several devices and
61files.
6dbe3af9 62
1581e22c
KZ
63.B swapoff
64disables swapping on the specified devices and files.
65When the
6dbe3af9 66.B \-a
1581e22c
KZ
67flag is given, swapping is disabled on all known swap devices and files
68(as found in
69.I /proc/swaps
70or
71.IR /etc/fstab ).
72
1f94a78c 73.SH OPTIONS
1581e22c 74.TP
1f94a78c 75.BR \-a , " \-\-all"
ce6479e2 76All devices marked as ``swap'' in
6dbe3af9 77.I /etc/fstab
d162fcb5 78are made available, except for those with the ``noauto'' option.
ce6479e2 79Devices that are already being used as swap are silently skipped.
c2301380 80.TP
1f94a78c 81.BR \-d , " \-\-discard" [ =\fIpolicy\fR]
d6387c98 82Enable swap discards, if the swap backing device supports the discard or
1f94a78c
BS
83trim operation. This may improve performance on some Solid State Devices,
84but often it does not. The option allows one to select between two
d6387c98 85available swap discard policies:
0bb7e904 86.B \-\-discard=once
d6387c98
RA
87to perform a single-time discard operation for the whole swap area at swapon;
88or
0bb7e904 89.B \-\-discard=pages
d35df4db 90to asynchronously discard freed swap pages before they are available for reuse.
d6387c98 91If no policy is selected, the default behavior is to enable both discard types.
c2301380
HD
92The
93.I /etc/fstab
d6387c98 94mount options
1f94a78c
BS
95.BR discard ,
96.BR discard=once ,
d6387c98 97or
1f94a78c
BS
98.B discard=pages
99may also be used to enable discard flags.
302e7b18 100.TP
1f94a78c 101.BR \-e , " \-\-ifexists"
ce6479e2 102Silently skip devices that do not exist.
a5fd3d68
KZ
103The
104.I /etc/fstab
105mount option
1f94a78c
BS
106.B nofail
107may also be used to skip non-existing device.
a5fd3d68 108
756bfd01 109.TP
1f94a78c 110.BR \-f , " \-\-fixpgsz"
f1bc5996 111Reinitialize (exec mkswap) the swap space if its page size does not
8d8ea18e 112match that of the current running kernel.
dbeb1d73 113.BR mkswap (8)
0d761944
KZ
114initializes the whole device and does not check for bad blocks.
115.TP
1f94a78c 116.BR \-h , " \-\-help"
b4362b6f 117Display help text and exit.
756bfd01 118.TP
1f94a78c 119.BI \-L " label"
756bfd01
KZ
120Use the partition that has the specified
121.IR label .
122(For this, access to
123.I /proc/partitions
124is needed.)
726f69e2 125.TP
e07fdac4 126.BR \-o , " \-\-options " \fIopts\fP
b1301d78
BS
127Specify swap options by an fstab-compatible comma-separated string.
128For example:
e07fdac4
KZ
129.RS
130.RS
131.sp
1c4c6024 132.B "swapon \-o pri=1,discard=pages,nofail /dev/sda2"
e07fdac4
KZ
133.sp
134.RE
b1301d78 135The \fIopts\fP string is evaluated last and overrides all other
6c44094a 136command line options.
e07fdac4
KZ
137.RE
138.TP
1f94a78c 139.BR \-p , " \-\-priority " \fIpriority\fP
1581e22c 140Specify the priority of the swap device.
fd6b7a7f 141.I priority
9404a96a
SK
142is a value between \-1 and 32767. Higher numbers indicate
143higher priority. See
fd6b7a7f 144.BR swapon (2)
1f94a78c 145for a full description of swap priorities. Add
fd6b7a7f
KZ
146.BI pri= value
147to the option field of
148.I /etc/fstab
149for use with
1c4c6024 150.BR "swapon \-a" .
b1301d78 151When no priority is defined, it defaults to \-1.
a47f2e66 152.TP
1f94a78c
BS
153.BR \-s , " \-\-summary"
154Display swap usage summary by device. Equivalent to "cat /proc/swaps".
9f3d0fce 155This output format is DEPRECATED in favour
a6c6662d 156of \fB\-\-show\fR that provides better control on output data.
756bfd01 157.TP
b1301d78
BS
158.BR \-\-show [ =\fIcolumn\fR ...]
159Display a definable table of swap areas. See the
1f94a78c
BS
160.B \-\-help
161output for a list of available columns.
e076b552 162.TP
b5b43f27
SK
163.B \-\-output\-all
164Output all available columns.
165.TP
e076b552
SK
166.B \-\-noheadings
167Do not print headings when displaying
168.B \-\-show
169output.
170.TP
171.B \-\-raw
172Display
173.B \-\-show
174output without aligning table columns.
175.TP
a68ca3a1 176.B \-\-bytes
7ae8b469
SK
177Display swap size in bytes in
178.B \-\-show
1f94a78c
BS
179output instead of in user-friendly units.
180.TP
181.BI \-U " uuid"
756bfd01
KZ
182Use the partition that has the specified
183.IR uuid .
756bfd01 184.TP
b1301d78 185.BR \-v , " \-\-verbose"
a47f2e66 186Be verbose.
756bfd01 187.TP
b1301d78 188.BR \-V , " \-\-version"
b4362b6f 189Display version information and exit.
67e63c12
MK
190.SH ENVIRONMENT
191.IP LIBMOUNT_DEBUG=all
192enables libmount debug output.
193.IP LIBBLKID_DEBUG=all
194enables libblkid debug output.
195
196.SH FILES
197.br
198.I /dev/sd??
199standard paging devices
200.br
201.I /etc/fstab
202ascii filesystem description table
1581e22c 203.SH NOTES
1895c76f 204.SS Files with holes
63391d75
MM
205The swap file implementation in the kernel expects to be able to write to the
206file directly, without the assistance of the filesystem. This is a problem on
207files with holes or on copy-on-write files on filesystems like Btrfs.
1895c76f 208.sp
63391d75 209Commands like
eebfa469 210.BR cp (1)
1895c76f
KZ
211or
212.BR truncate (1)
213create files with holes. These files will be rejected by swapon.
214.sp
63391d75
MM
215Preallocated files created by
216.BR fallocate (1)
217may be interpreted as files with holes too depending of the filesystem.
218Preallocated swap files are supported on XFS since Linux 4.18.
1895c76f
KZ
219.sp
220The most portable solution to create a swap file is to use
24930e70 221.BR dd (1)
63391d75 222and /dev/zero.
1895c76f 223.SS Btrfs
63391d75
MM
224Swap files on Btrfs are supported since Linux 5.0 on files with nocow attribute.
225See the
226.BR btrfs (5)
227manual page for more details.
1895c76f 228.SS NFS
03b5e597 229Swap over \fBNFS\fR may not work.
1895c76f 230.SS Suspend
1581e22c 231.B swapon
24930e70 232automatically detects and rewrites a swap space signature with old software
eb024893 233suspend data (e.g., S1SUSPEND, S2SUSPEND, ...). The problem is that if we don't
1581e22c
KZ
234do it, then we get data corruption the next time an attempt at unsuspending is
235made.
6dbe3af9
KZ
236.SH HISTORY
237The
238.B swapon
239command appeared in 4.0BSD.
ade04bb8
MK
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)
86d62711 249.SH AVAILABILITY
601d12fb 250The swapon command is part of the util-linux package and is available from
d673b74e 251https://www.kernel.org/pub/linux/utils/util-linux/.