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 --noheadings
92 Do not print headings when displaying --show output.
93
94 --raw Display --show output without aligning table columns.
95
96 --bytes
97 Display swap size in bytes in --show output instead of in user-
98 friendly units.
99
100 -U uuid
101 Use the partition that has the specified uuid.
102
103 -v, --verbose
104 Be verbose.
105
106 -V, --version
107 Display version information and exit.
108
110 You should not use swapon on a file with holes. This can be seen in
111 the system log as
112
113 swapon: swapfile has holes.
114
115 The swap file implementation in the kernel expects to be able to write
116 to the file directly, without the assistance of the filesystem. This
117 is a problem on preallocated files (e.g. fallocate(1)) on filesystems
118 like XFS or ext4, and on copy-on-write filesystems like btrfs.
119
120 It is recommended to use dd(1) and /dev/zero to avoid holes on XFS and
121 ext4.
122
123 swapon may not work correctly when using a swap file with some versions
124 of btrfs. This is due to btrfs being a copy-on-write filesystem: the
125 file location may not be static and corruption can result. Btrfs
126 actively disallows the use of swap files on its filesystems by refusing
127 to map the file.
128
129 One possible workaround is to map the swap file to a loopback device.
130 This will allow the filesystem to determine the mapping properly but
131 may come with a performance impact.
132
133 Swap over NFS may not work.
134
135 swapon automatically detects and rewrites a swap space signature with
136 old software suspend data (e.g S1SUSPEND, S2SUSPEND, ...). The problem
137 is that if we don't do it, then we get data corruption the next time an
138 attempt at unsuspending is made.
139
140
142 LIBMOUNT_DEBUG=all
143 enables libmount debug output.
144
145 LIBBLKID_DEBUG=all
146 enables libblkid debug output.
147
148
150 swapoff(2), swapon(2), fstab(5), init(8), mkswap(8), mount(8), rc(8)
151
153 /dev/sd?? standard paging devices
154 /etc/fstab ascii filesystem description table
155
157 The swapon command appeared in 4.0BSD.
158
160 The swapon command is part of the util-linux package and is available
161 from https://www.kernel.org/pub/linux/utils/util-linux/.
162
163
164
165util-linux October 2014 SWAPON(8)