{
    "content": [
        {
            "type": "text",
            "text": "# swapon(8) (man)\n\n**Summary:** swapon, swapoff - enable/disable devices and files for paging and swapping\n\n**Synopsis:** swapon [options] [specialfile...]\nswapoff [-va] [specialfile...]\n\n## Flags\n\n| Flag | Long | Arg | Description |\n|------|------|-----|-------------|\n| -a | --all | — | All devices marked as \"swap\" in /etc/fstab are made available, except for those with the \"noauto\" option. Devices that a |\n| -d | --discard | — | Enable swap discards, if the swap backing device supports the discard or trim operation. This may improve performance on |\n| -e | --ifexists | — | Silently skip devices that do not exist. The /etc/fstab mount option nofail may also be used to skip non-existing device |\n| -f | --fixpgsz | — | Reinitialize (exec mkswap) the swap space if its page size does not match that of the current running kernel. mkswap(8)  |\n| -h | --help | — | Display help text and exit. |\n| -L | — | — | Use the partition that has the specified label. (For this, access to /proc/partitions is needed.) |\n| -o | --options | — | Specify swap options by an fstab-compatible comma-separated string. For example: swapon -o pri=1,discard=pages,nofail /d |\n| -p | --priority | — | Specify the priority of the swap device. priority is a value between -1 and 32767. Higher numbers indicate higher priori |\n| -s | --summary | — | Display swap usage summary by device. Equivalent to cat /proc/swaps. This output format is DEPRECATED in favour of --sho |\n| — | --output-all | — | Output all available columns. |\n| — | --noheadings | — | Do not print headings when displaying --show output. |\n| — | --raw | — | Display --show output without aligning table columns. |\n| — | --bytes | — | Display swap size in bytes in --show output instead of in user-friendly units. |\n| -U | — | — | Use the partition that has the specified uuid. |\n| -v | --verbose | — | Be verbose. |\n| -V | --version | — | Display version information and exit. |\n\n## See Also\n\n- swapoff(2)\n- fstab(5)\n- init(8)\n- fallocate(1)\n- mkswap(8)\n- mount(8)\n- rc(8)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (4 lines)\n- **DESCRIPTION** (12 lines)\n- **OPTIONS** (1 lines) — 16 subsections\n  - -a --all (3 lines)\n  - -d --discard (14 lines)\n  - -e --ifexists (3 lines)\n  - -f --fixpgsz (4 lines)\n  - -h --help (2 lines)\n  - -L (3 lines)\n  - -o --options (6 lines)\n  - -p --priority (5 lines)\n  - -s --summary (7 lines)\n  - --output-all (2 lines)\n  - --noheadings (2 lines)\n  - --raw (2 lines)\n  - --bytes (2 lines)\n  - -U (2 lines)\n  - -v --verbose (2 lines)\n  - -V --version (2 lines)\n- **EXIT STATUS** (29 lines)\n- **ENVIRONMENT** (6 lines)\n- **FILES** (6 lines)\n- **NOTES** (1 lines) — 3 subsections\n  - Files with holes (12 lines)\n  - Btrfs (6 lines)\n  - Suspend (4 lines)\n- **HISTORY** (2 lines)\n- **SEE ALSO** (2 lines)\n- **REPORTING BUGS** (2 lines)\n- **AVAILABILITY** (6 lines)\n\n## Full Content\n\n### NAME\n\nswapon, swapoff - enable/disable devices and files for paging and swapping\n\n### SYNOPSIS\n\nswapon [options] [specialfile...]\n\nswapoff [-va] [specialfile...]\n\n### DESCRIPTION\n\nswapon is used to specify devices on which paging and swapping are to take place.\n\nThe device or file used is given by the specialfile parameter. It may be of the form -L label\nor -U uuid to indicate a device by label or uuid.\n\nCalls to swapon normally occur in the system boot scripts making all swap devices available,\nso that the paging and swapping activity is interleaved across several devices and files.\n\nswapoff disables swapping on the specified devices and files. When the -a flag is given,\nswapping is disabled on all known swap devices and files (as found in /proc/swaps or\n/etc/fstab).\n\n### OPTIONS\n\n#### -a --all\n\nAll devices marked as \"swap\" in /etc/fstab are made available, except for those with the\n\"noauto\" option. Devices that are already being used as swap are silently skipped.\n\n#### -d --discard\n\nEnable swap discards, if the swap backing device supports the discard or trim operation.\nThis may improve performance on some Solid State Devices, but often it does not. The\noption allows one to select between two available swap discard policies:\n\n--discard=once\nto perform a single-time discard operation for the whole swap area at swapon; or\n\n--discard=pages\nto asynchronously discard freed swap pages before they are available for reuse.\n\nIf no policy is selected, the default behavior is to enable both discard types. The\n/etc/fstab mount options discard, discard=once, or discard=pages may also be used to\nenable discard flags.\n\n#### -e --ifexists\n\nSilently skip devices that do not exist. The /etc/fstab mount option nofail may also be\nused to skip non-existing device.\n\n#### -f --fixpgsz\n\nReinitialize (exec mkswap) the swap space if its page size does not match that of the\ncurrent running kernel. mkswap(8) initializes the whole device and does not check for bad\nblocks.\n\n#### -h --help\n\nDisplay help text and exit.\n\n#### -L\n\nUse the partition that has the specified label. (For this, access to /proc/partitions is\nneeded.)\n\n#### -o --options\n\nSpecify swap options by an fstab-compatible comma-separated string. For example:\n\nswapon -o pri=1,discard=pages,nofail /dev/sda2\n\nThe opts string is evaluated last and overrides all other command line options.\n\n#### -p --priority\n\nSpecify the priority of the swap device. priority is a value between -1 and 32767. Higher\nnumbers indicate higher priority. See swapon(2) for a full description of swap\npriorities. Add pri=value to the option field of /etc/fstab for use with swapon -a. When\nno priority is defined, it defaults to -1.\n\n#### -s --summary\n\nDisplay swap usage summary by device. Equivalent to cat /proc/swaps. This output format\nis DEPRECATED in favour of --show that provides better control on output data.\n\n--show[=column...]\nDisplay a definable table of swap areas. See the --help output for a list of available\ncolumns.\n\n#### --output-all\n\nOutput all available columns.\n\n#### --noheadings\n\nDo not print headings when displaying --show output.\n\n#### --raw\n\nDisplay --show output without aligning table columns.\n\n#### --bytes\n\nDisplay swap size in bytes in --show output instead of in user-friendly units.\n\n#### -U\n\nUse the partition that has the specified uuid.\n\n#### -v --verbose\n\nBe verbose.\n\n#### -V --version\n\nDisplay version information and exit.\n\n### EXIT STATUS\n\nswapoff has the following exit status values since v2.36:\n\n0\nsuccess\n\n2\nsystem has insufficient memory to stop swapping (OOM)\n\n4\nswapoff syscall failed for another reason\n\n8\nnon-swapoff syscall system error (out of memory, ...)\n\n16\nusage or syntax error\n\n32\nall swapoff failed on --all\n\n64\nsome swapoff succeeded on --all\n\nThe command swapoff --all returns 0 (all succeeded), 32 (all failed), or 64 (some failed,\nsome succeeded).\n\n+ The old versions before v2.36 has no documented exit status, 0 means success in all\nversions.\n\n### ENVIRONMENT\n\nLIBMOUNTDEBUG=all\nenables libmount debug output.\n\nLIBBLKIDDEBUG=all\nenables libblkid debug output.\n\n### FILES\n\n/dev/sd??\nstandard paging devices\n\n/etc/fstab\nascii filesystem description table\n\n### NOTES\n\n#### Files with holes\n\nThe swap file implementation in the kernel expects to be able to write to the file directly,\nwithout the assistance of the filesystem. This is a problem on files with holes or on\ncopy-on-write files on filesystems like Btrfs.\n\nCommands like cp(1) or truncate(1) create files with holes. These files will be rejected by\nswapon.\n\nPreallocated files created by fallocate(1) may be interpreted as files with holes too\ndepending of the filesystem. Preallocated swap files are supported on XFS since Linux 4.18.\n\nThe most portable solution to create a swap file is to use dd(1) and /dev/zero.\n\n#### Btrfs\n\nSwap files on Btrfs are supported since Linux 5.0 on files with nocow attribute. See the\nbtrfs(5) manual page for more details.\n\nNFS\nSwap over NFS may not work.\n\n#### Suspend\n\nswapon automatically detects and rewrites a swap space signature with old software suspend\ndata (e.g., S1SUSPEND, S2SUSPEND, ...). The problem is that if we don’t do it, then we get\ndata corruption the next time an attempt at unsuspending is made.\n\n### HISTORY\n\nThe swapon command appeared in 4.0BSD.\n\n### SEE ALSO\n\nswapoff(2), swapon(2), fstab(5), init(8), fallocate(1), mkswap(8), mount(8), rc(8)\n\n### REPORTING BUGS\n\nFor bug reports, use the issue tracker at https://github.com/karelzak/util-linux/issues.\n\n### AVAILABILITY\n\nThe swapon command is part of the util-linux package which can be downloaded from Linux\nKernel Archive <https://www.kernel.org/pub/linux/utils/util-linux/>.\n\n\n\nutil-linux 2.37.2                            2021-06-02                                    SWAPON(8)\n\n"
        }
    ],
    "structuredContent": {
        "command": "swapon",
        "section": "8",
        "mode": "man",
        "summary": "swapon, swapoff - enable/disable devices and files for paging and swapping",
        "synopsis": "swapon [options] [specialfile...]\nswapoff [-va] [specialfile...]",
        "flags": [
            {
                "flag": "-a",
                "long": "--all",
                "arg": null,
                "description": "All devices marked as \"swap\" in /etc/fstab are made available, except for those with the \"noauto\" option. Devices that are already being used as swap are silently skipped."
            },
            {
                "flag": "-d",
                "long": "--discard",
                "arg": null,
                "description": "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: --discard=once to perform a single-time discard operation for the whole swap area at swapon; or --discard=pages 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 /etc/fstab mount options discard, discard=once, or discard=pages may also be used to enable discard flags."
            },
            {
                "flag": "-e",
                "long": "--ifexists",
                "arg": null,
                "description": "Silently skip devices that do not exist. The /etc/fstab mount option nofail may also be used to skip non-existing device."
            },
            {
                "flag": "-f",
                "long": "--fixpgsz",
                "arg": null,
                "description": "Reinitialize (exec mkswap) the swap space if its page size does not match that of the current running kernel. mkswap(8) initializes the whole device and does not check for bad blocks."
            },
            {
                "flag": "-h",
                "long": "--help",
                "arg": null,
                "description": "Display help text and exit."
            },
            {
                "flag": "-L",
                "long": null,
                "arg": null,
                "description": "Use the partition that has the specified label. (For this, access to /proc/partitions is needed.)"
            },
            {
                "flag": "-o",
                "long": "--options",
                "arg": null,
                "description": "Specify swap options by an fstab-compatible comma-separated string. For example: swapon -o pri=1,discard=pages,nofail /dev/sda2 The opts string is evaluated last and overrides all other command line options."
            },
            {
                "flag": "-p",
                "long": "--priority",
                "arg": null,
                "description": "Specify the priority of the swap device. priority is a value between -1 and 32767. Higher numbers indicate higher priority. See swapon(2) for a full description of swap priorities. Add pri=value to the option field of /etc/fstab for use with swapon -a. When no priority is defined, it defaults to -1."
            },
            {
                "flag": "-s",
                "long": "--summary",
                "arg": null,
                "description": "Display swap usage summary by device. Equivalent to cat /proc/swaps. This output format is DEPRECATED in favour of --show that provides better control on output data. --show[=column...] Display a definable table of swap areas. See the --help output for a list of available columns."
            },
            {
                "flag": "",
                "long": "--output-all",
                "arg": null,
                "description": "Output all available columns."
            },
            {
                "flag": "",
                "long": "--noheadings",
                "arg": null,
                "description": "Do not print headings when displaying --show output."
            },
            {
                "flag": "",
                "long": "--raw",
                "arg": null,
                "description": "Display --show output without aligning table columns."
            },
            {
                "flag": "",
                "long": "--bytes",
                "arg": null,
                "description": "Display swap size in bytes in --show output instead of in user-friendly units."
            },
            {
                "flag": "-U",
                "long": null,
                "arg": null,
                "description": "Use the partition that has the specified uuid."
            },
            {
                "flag": "-v",
                "long": "--verbose",
                "arg": null,
                "description": "Be verbose."
            },
            {
                "flag": "-V",
                "long": "--version",
                "arg": null,
                "description": "Display version information and exit."
            }
        ],
        "examples": [],
        "see_also": [
            {
                "name": "swapoff",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/swapoff/2/json"
            },
            {
                "name": "fstab",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/fstab/5/json"
            },
            {
                "name": "init",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/init/8/json"
            },
            {
                "name": "fallocate",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/fallocate/1/json"
            },
            {
                "name": "mkswap",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/mkswap/8/json"
            },
            {
                "name": "mount",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/mount/8/json"
            },
            {
                "name": "rc",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/rc/8/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "-a --all",
                        "lines": 3,
                        "flag": "-a",
                        "long": "--all"
                    },
                    {
                        "name": "-d --discard",
                        "lines": 14,
                        "flag": "-d",
                        "long": "--discard"
                    },
                    {
                        "name": "-e --ifexists",
                        "lines": 3,
                        "flag": "-e",
                        "long": "--ifexists"
                    },
                    {
                        "name": "-f --fixpgsz",
                        "lines": 4,
                        "flag": "-f",
                        "long": "--fixpgsz"
                    },
                    {
                        "name": "-h --help",
                        "lines": 2,
                        "flag": "-h",
                        "long": "--help"
                    },
                    {
                        "name": "-L",
                        "lines": 3,
                        "flag": "-L"
                    },
                    {
                        "name": "-o --options",
                        "lines": 6,
                        "flag": "-o",
                        "long": "--options"
                    },
                    {
                        "name": "-p --priority",
                        "lines": 5,
                        "flag": "-p",
                        "long": "--priority"
                    },
                    {
                        "name": "-s --summary",
                        "lines": 7,
                        "flag": "-s",
                        "long": "--summary"
                    },
                    {
                        "name": "--output-all",
                        "lines": 2,
                        "long": "--output-all"
                    },
                    {
                        "name": "--noheadings",
                        "lines": 2,
                        "long": "--noheadings"
                    },
                    {
                        "name": "--raw",
                        "lines": 2,
                        "long": "--raw"
                    },
                    {
                        "name": "--bytes",
                        "lines": 2,
                        "long": "--bytes"
                    },
                    {
                        "name": "-U",
                        "lines": 2,
                        "flag": "-U"
                    },
                    {
                        "name": "-v --verbose",
                        "lines": 2,
                        "flag": "-v",
                        "long": "--verbose"
                    },
                    {
                        "name": "-V --version",
                        "lines": 2,
                        "flag": "-V",
                        "long": "--version"
                    }
                ]
            },
            {
                "name": "EXIT STATUS",
                "lines": 29,
                "subsections": []
            },
            {
                "name": "ENVIRONMENT",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "FILES",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Files with holes",
                        "lines": 12
                    },
                    {
                        "name": "Btrfs",
                        "lines": 6
                    },
                    {
                        "name": "Suspend",
                        "lines": 4
                    }
                ]
            },
            {
                "name": "HISTORY",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "REPORTING BUGS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AVAILABILITY",
                "lines": 6,
                "subsections": []
            }
        ]
    }
}