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(2) 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 You should not use swapon on a file with holes. This can be seen in
114 the system log as
115
116 swapon: swapfile has holes.
117
118 The swap file implementation in the kernel expects to be able to write
119 to the file directly, without the assistance of the filesystem. This
120 is a problem on preallocated files (e.g. fallocate(1)) on filesystems
121 like XFS or ext4, and on copy-on-write filesystems like btrfs.
122
123 It is recommended to use dd(1) and /dev/zero to avoid holes on XFS and
124 ext4.
125
126 swapon may not work correctly when using a swap file with some versions
127 of btrfs. This is due to btrfs being a copy-on-write filesystem: the
128 file location may not be static and corruption can result. Btrfs
129 actively disallows the use of swap files on its filesystems by refusing
130 to map the file.
131
132 One possible workaround is to map the swap file to a loopback device.
133 This will allow the filesystem to determine the mapping properly but
134 may come with a performance impact.
135
136 Swap over NFS may not work.
137
138 swapon automatically detects and rewrites a swap space signature with
139 old software suspend data (e.g. S1SUSPEND, S2SUSPEND, ...). The problem
140 is that if we don't do it, then we get data corruption the next time an
141 attempt at unsuspending is made.
142
143
145 LIBMOUNT_DEBUG=all
146 enables libmount debug output.
147
148 LIBBLKID_DEBUG=all
149 enables libblkid debug output.
150
151
153 swapoff(2), swapon(2), fstab(5), init(8), mkswap(8), mount(8), rc(8)
154
156 /dev/sd?? standard paging devices
157 /etc/fstab ascii filesystem description table
158
160 The swapon command appeared in 4.0BSD.
161
163 The swapon command is part of the util-linux package and is available
164 from https://www.kernel.org/pub/linux/utils/util-linux/.
165
166
167
168util-linux October 2014 SWAPON(8)