{
    "mode": "man",
    "parameter": "mkswap",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/mkswap/8/json",
    "generated": "2026-05-30T07:10:24Z",
    "synopsis": "mkswap [options] device [size]",
    "sections": {
        "NAME": {
            "content": "mkswap - set up a Linux swap area\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "mkswap [options] device [size]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "mkswap sets up a Linux swap area on a device or in a file.\n\nThe device argument will usually be a disk partition (something like /dev/sdb7) but can also\nbe a file. The Linux kernel does not look at partition IDs, but many installation scripts\nwill assume that partitions of hex type 82 (LINUXSWAP) are meant to be swap partitions.\n(Warning: Solaris also uses this type. Be careful not to kill your Solaris partitions.)\n\nThe size parameter is superfluous but retained for backwards compatibility. (It specifies the\ndesired size of the swap area in 1024-byte blocks. mkswap will use the entire partition or\nfile if it is omitted. Specifying it is unwise - a typo may destroy your disk.)\n\nAfter creating the swap area, you need the swapon command to start using it. Usually swap\nareas are listed in /etc/fstab so that they can be taken into use at boot time by a swapon -a\ncommand in some boot script.\n",
            "subsections": []
        },
        "WARNING": {
            "content": "The swap header does not touch the first block. A boot loader or disk label can be there, but\nit is not a recommended setup. The recommended setup is to use a separate partition for a\nLinux swap area.\n\nmkswap, like many others mkfs-like utils, erases the first partition block to make any",
            "subsections": [
                {
                    "name": "previous filesystem invisible.",
                    "content": "However, mkswap refuses to erase the first block on a device with a disk label (SUN, BSD,\n...).\n"
                }
            ]
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "-c --check",
                    "content": "Check the device (if it is a block device) for bad blocks before creating the swap area.\nIf any bad blocks are found, the count is printed.\n",
                    "flag": "-c",
                    "long": "--check"
                },
                {
                    "name": "-f --force",
                    "content": "Go ahead even if the command is stupid. This allows the creation of a swap area larger\nthan the file or partition it resides on.\n\nAlso, without this option, mkswap will refuse to erase the first block on a device with a\npartition table.\n",
                    "flag": "-f",
                    "long": "--force"
                },
                {
                    "name": "-L --label",
                    "content": "Specify a label for the device, to allow swapon by label.\n\n--lock[=mode]\nUse exclusive BSD lock for device or file it operates. The optional argument mode can be\nyes, no (or 1 and 0) or nonblock. If the mode argument is omitted, it defaults to \"yes\".\nThis option overwrites environment variable $LOCKBLOCKDEVICE. The default is not to use\nany lock at all, but it’s recommended to avoid collisions with udevd or other tools.\n",
                    "flag": "-L",
                    "long": "--label"
                },
                {
                    "name": "-p --pagesize",
                    "content": "Specify the page size (in bytes) to use. This option is usually unnecessary; mkswap reads\nthe size from the kernel.\n",
                    "flag": "-p",
                    "long": "--pagesize"
                },
                {
                    "name": "-U --uuid",
                    "content": "Specify the UUID to use. The default is to generate a UUID.\n",
                    "flag": "-U",
                    "long": "--uuid"
                },
                {
                    "name": "-v --swapversion",
                    "content": "Specify the swap-space version. (This option is currently pointless, as the old -v 0\noption has become obsolete and now only -v 1 is supported. The kernel has not supported\nv0 swap-space format since 2.5.22 (June 2002). The new version v1 is supported since\n2.1.117 (August 1998).)\n",
                    "flag": "-v",
                    "long": "--swapversion"
                },
                {
                    "name": "--verbose",
                    "content": "Verbose execution. With this option mkswap will output more details about detected\nproblems during swap area set up.\n",
                    "long": "--verbose"
                },
                {
                    "name": "-h --help",
                    "content": "Display help text and exit.\n",
                    "flag": "-h",
                    "long": "--help"
                },
                {
                    "name": "-V --version",
                    "content": "Display version information and exit.\n",
                    "flag": "-V",
                    "long": "--version"
                }
            ]
        },
        "ENVIRONMENT": {
            "content": "LIBBLKIDDEBUG=all\nenables libblkid debug output.\n\nLOCKBLOCKDEVICE=<mode>\nuse exclusive BSD lock. The mode is \"1\" or \"0\". See --lock for more details.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "The maximum useful size of a swap area depends on the architecture and the kernel version.\n\nThe maximum number of the pages that is possible to address by swap area header is 4294967295\n(32-bit unsigned int). The remaining space on the swap device is ignored.\n\nPresently, Linux allows 32 swap areas. The areas in use can be seen in the file /proc/swaps.\n\nmkswap refuses areas smaller than 10 pages.\n\nIf you don’t know the page size that your machine uses, you may be able to look it up with\ncat /proc/cpuinfo (or you may not - the contents of this file depend on architecture and\nkernel version).\n\nTo set up a swap file, it is necessary to create that file before initializing it with\nmkswap, e.g. using a command like\n\n# dd if=/dev/zero of=swapfile bs=1MiB count=$((8*1024))\n\nto create 8GiB swapfile.\n\nPlease read notes from swapon(8) about the swap file use restrictions (holes, preallocation\nand copy-on-write issues).\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "fdisk(8), swapon(8)\n",
            "subsections": []
        },
        "REPORTING BUGS": {
            "content": "For bug reports, use the issue tracker at https://github.com/karelzak/util-linux/issues.\n",
            "subsections": []
        },
        "AVAILABILITY": {
            "content": "The mkswap 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                                    MKSWAP(8)",
            "subsections": []
        }
    },
    "summary": "mkswap - set up a Linux swap area",
    "flags": [
        {
            "flag": "-c",
            "long": "--check",
            "arg": null,
            "description": "Check the device (if it is a block device) for bad blocks before creating the swap area. If any bad blocks are found, the count is printed."
        },
        {
            "flag": "-f",
            "long": "--force",
            "arg": null,
            "description": "Go ahead even if the command is stupid. This allows the creation of a swap area larger than the file or partition it resides on. Also, without this option, mkswap will refuse to erase the first block on a device with a partition table."
        },
        {
            "flag": "-L",
            "long": "--label",
            "arg": null,
            "description": "Specify a label for the device, to allow swapon by label. --lock[=mode] Use exclusive BSD lock for device or file it operates. The optional argument mode can be yes, no (or 1 and 0) or nonblock. If the mode argument is omitted, it defaults to \"yes\". This option overwrites environment variable $LOCKBLOCKDEVICE. The default is not to use any lock at all, but it’s recommended to avoid collisions with udevd or other tools."
        },
        {
            "flag": "-p",
            "long": "--pagesize",
            "arg": null,
            "description": "Specify the page size (in bytes) to use. This option is usually unnecessary; mkswap reads the size from the kernel."
        },
        {
            "flag": "-U",
            "long": "--uuid",
            "arg": null,
            "description": "Specify the UUID to use. The default is to generate a UUID."
        },
        {
            "flag": "-v",
            "long": "--swapversion",
            "arg": null,
            "description": "Specify the swap-space version. (This option is currently pointless, as the old -v 0 option has become obsolete and now only -v 1 is supported. The kernel has not supported v0 swap-space format since 2.5.22 (June 2002). The new version v1 is supported since 2.1.117 (August 1998).)"
        },
        {
            "flag": "",
            "long": "--verbose",
            "arg": null,
            "description": "Verbose execution. With this option mkswap will output more details about detected problems during swap area set up."
        },
        {
            "flag": "-h",
            "long": "--help",
            "arg": null,
            "description": "Display help text and exit."
        },
        {
            "flag": "-V",
            "long": "--version",
            "arg": null,
            "description": "Display version information and exit."
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "fdisk",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/fdisk/8/json"
        },
        {
            "name": "swapon",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/swapon/8/json"
        }
    ]
}