man-pages/man8/swapon.8.html
2021-03-31 01:06:50 +01:00

363 lines
8.3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SWAPON</TITLE>
</HEAD><BODY>
<H1>SWAPON</H1>
Section: System Administration (8)<BR>Updated: October 2014<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
swapon, swapoff - enable/disable devices and files for paging and swapping
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>swapon</B>
[options]
[<I>specialfile</I>...]
<BR>
<B>swapoff</B>
[<B>-va</B>]
[<I>specialfile</I>...]
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>swapon</B>
is used to specify devices on which paging and swapping are to take place.
<P>
The device or file used is given by the
<I>specialfile</I>
parameter. It may be of the form
<B>-L</B><I> label</I>
or
<B>-U</B><I> uuid</I>
to indicate a device by label or uuid.
<P>
Calls to
<B>swapon</B>
normally occur in the system boot scripts making all swap devices available, so
that the paging and swapping activity is interleaved across several devices and
files.
<P>
<B>swapoff</B>
disables swapping on the specified devices and files.
When the
<B>-a</B>
flag is given, swapping is disabled on all known swap devices and files
(as found in
<I>/proc/swaps</I>
or
<I>/etc/fstab</I>).
<P>
<A NAME="lbAE">&nbsp;</A>
<H2>OPTIONS</H2>
<DL COMPACT>
<DT id="1"><B>-a</B>,<B> --all</B>
<DD>
All devices marked as ``swap'' in
<I>/etc/fstab</I>
are made available, except for those with the ``noauto'' option.
Devices that are already being used as swap are silently skipped.
<DT id="2"><B>-d</B>,<B> --discard</B>[<B>=</B><I>policy</I>]
<DD>
Enable swap discards, if the swap backing device supports the discard or
trim operation. This may improve performance on some Solid State Devices,
but often it does not. The option allows one to select between two
available swap discard policies:
<B>--discard=once</B>
to perform a single-time discard operation for the whole swap area at swapon;
or
<B>--discard=pages</B>
to asynchronously discard freed swap pages before they are available for reuse.
If no policy is selected, the default behavior is to enable both discard types.
The
<I>/etc/fstab</I>
mount options
<B>discard</B>,
<B>discard=once</B>,
or
<B>discard=pages</B>
may also be used to enable discard flags.
<DT id="3"><B>-e</B>,<B> --ifexists</B>
<DD>
Silently skip devices that do not exist.
The
<I>/etc/fstab</I>
mount option
<B>nofail</B>
may also be used to skip non-existing device.
<P>
<DT id="4"><B>-f</B>,<B> --fixpgsz</B>
<DD>
Reinitialize (exec mkswap) the swap space if its page size does not
match that of the current running kernel.
<B><A HREF="/cgi-bin/man/man2html?2+mkswap">mkswap</A></B>(2)
initializes the whole device and does not check for bad blocks.
<DT id="5"><B>-h</B>,<B> --help</B>
<DD>
Display help text and exit.
<DT id="6"><B>-L</B><I> label</I>
<DD>
Use the partition that has the specified
<I>label</I>.
(For this, access to
<I>/proc/partitions</I>
is needed.)
<DT id="7"><B>-o</B>,<B> --options </B><I>opts</I>
<DD>
Specify swap options by an fstab-compatible comma-separated string.
For example:
<DL COMPACT><DT id="8"><DD>
<DL COMPACT><DT id="9"><DD>
<P>
<B>swapon -o pri=1,discard=pages,nofail /dev/sda2</B>
<P>
</DL>
The <I>opts</I> string is evaluated last and overrides all other
command line options.
</DL>
<DT id="10"><B>-p</B>,<B> --priority </B><I>priority</I>
<DD>
Specify the priority of the swap device.
<I>priority</I>
is a value between -1 and 32767. Higher numbers indicate
higher priority. See
<B><A HREF="/cgi-bin/man/man2html?2+swapon">swapon</A></B>(2)
for a full description of swap priorities. Add
<B>pri=</B><I>value</I>
to the option field of
<I>/etc/fstab</I>
for use with
<B>swapon -a</B>.
When no priority is defined, it defaults to -1.
<DT id="11"><B>-s</B>,<B> --summary</B>
<DD>
Display swap usage summary by device. Equivalent to &quot;cat /proc/swaps&quot;.
This output format is DEPRECATED in favour
of <B>--show</B> that provides better control on output data.
<DT id="12"><B>--show</B>[<B>=</B><I>column</I>...]
<DD>
Display a definable table of swap areas. See the
<B>--help</B>
output for a list of available columns.
<DT id="13"><B>--output-all</B>
<DD>
Output all available columns.
<DT id="14"><B>--noheadings</B>
<DD>
Do not print headings when displaying
<B>--show</B>
output.
<DT id="15"><B>--raw</B>
<DD>
Display
<B>--show</B>
output without aligning table columns.
<DT id="16"><B>--bytes</B>
<DD>
Display swap size in bytes in
<B>--show</B>
output instead of in user-friendly units.
<DT id="17"><B>-U</B><I> uuid</I>
<DD>
Use the partition that has the specified
<I>uuid</I>.
<DT id="18"><B>-v</B>,<B> --verbose</B>
<DD>
Be verbose.
<DT id="19"><B>-V</B>,<B> --version</B>
<DD>
Display version information and exit.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>NOTES</H2>
<A NAME="lbAG">&nbsp;</A>
<H3>Files with holes</H3>
The swap file implementation in the kernel expects to be able to write to the
file directly, without the assistance of the filesystem. This is a problem on
files with holes or on copy-on-write files on filesystems like Btrfs.
<P>
Commands like
<B><A HREF="/cgi-bin/man/man2html?1+cp">cp</A></B>(1)
or
<B><A HREF="/cgi-bin/man/man2html?1+truncate">truncate</A></B>(1)
create files with holes. These files will be rejected by swapon.
<P>
Preallocated files created by
<B><A HREF="/cgi-bin/man/man2html?1+fallocate">fallocate</A></B>(1)
may be interpreted as files with holes too depending of the filesystem.
Preallocated swap files are supported on XFS since Linux 4.18.
<P>
The most portable solution to create a swap file is to use
<B><A HREF="/cgi-bin/man/man2html?1+dd">dd</A></B>(1)
and /dev/zero.
<A NAME="lbAH">&nbsp;</A>
<H3>Btrfs</H3>
Swap files on Btrfs are supported since Linux 5.0 on files with nocow attribute.
See the
<B><A HREF="/cgi-bin/man/man2html?5+btrfs">btrfs</A></B>(5)
manual page for more details.
<A NAME="lbAI">&nbsp;</A>
<H3>NFS</H3>
Swap over <B>NFS</B> may not work.
<A NAME="lbAJ">&nbsp;</A>
<H3>Suspend</H3>
<B>swapon</B>
automatically detects and rewrites a swap space signature with old software
suspend data (e.g. S1SUSPEND, S2SUSPEND, ...). The problem is that if we don't
do it, then we get data corruption the next time an attempt at unsuspending is
made.
<A NAME="lbAK">&nbsp;</A>
<H2>ENVIRONMENT</H2>
<DL COMPACT>
<DT id="20">LIBMOUNT_DEBUG=all<DD>
enables libmount debug output.
<DT id="21">LIBBLKID_DEBUG=all<DD>
enables libblkid debug output.
<P>
</DL>
<A NAME="lbAL">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+swapoff">swapoff</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+swapon">swapon</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?5+fstab">fstab</A></B>(5),
<B><A HREF="/cgi-bin/man/man2html?8+init">init</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?1+fallocate">fallocate</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?8+mkswap">mkswap</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?8+mount">mount</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?8+rc">rc</A></B>(8)
<A NAME="lbAM">&nbsp;</A>
<H2>FILES</H2>
<BR>
<I>/dev/sd??</I>
standard paging devices
<BR>
<I>/etc/fstab</I>
ascii filesystem description table
<A NAME="lbAN">&nbsp;</A>
<H2>HISTORY</H2>
The
<B>swapon</B>
command appeared in 4.0BSD.
<A NAME="lbAO">&nbsp;</A>
<H2>AVAILABILITY</H2>
The swapon command is part of the util-linux package and is available from
<A HREF="https://www.kernel.org/pub/linux/utils/util-linux/.">https://www.kernel.org/pub/linux/utils/util-linux/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="22"><A HREF="#lbAB">NAME</A><DD>
<DT id="23"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="24"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="25"><A HREF="#lbAE">OPTIONS</A><DD>
<DT id="26"><A HREF="#lbAF">NOTES</A><DD>
<DL>
<DT id="27"><A HREF="#lbAG">Files with holes</A><DD>
<DT id="28"><A HREF="#lbAH">Btrfs</A><DD>
<DT id="29"><A HREF="#lbAI">NFS</A><DD>
<DT id="30"><A HREF="#lbAJ">Suspend</A><DD>
</DL>
<DT id="31"><A HREF="#lbAK">ENVIRONMENT</A><DD>
<DT id="32"><A HREF="#lbAL">SEE ALSO</A><DD>
<DT id="33"><A HREF="#lbAM">FILES</A><DD>
<DT id="34"><A HREF="#lbAN">HISTORY</A><DD>
<DT id="35"><A HREF="#lbAO">AVAILABILITY</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:06:16 GMT, March 31, 2021
</BODY>
</HTML>