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