MKSWAP(8)
๐ MKSWAP(8) โ aka mkswap, the swap-area glow-up station โจ
okay bestie, welcome to the System Administration section of the manual, this is mkswap(8) and she is iconic ๐
โจ NAME โจ
mkswap โ set up a Linux swap area ๐ซถ
๐ธ SYNOPSIS ๐ธ
mkswap [options] device [blocks]
mkswap [options] --size size --file file
๐ฆ DESCRIPTION ๐ฆ
So like, mkswap sets up a Linux swap area on a device or in a file. That's the whole job. That's her main character arc. ๐
The device argument is usually gonna be a disk partition (something like /dev/sdb7) but ngl it can also totally be a file. Here's the tea though: the Linux kernel itself does not look at partition IDs, but a bunch of installation scripts will just assume that partitions of hex type 82 (LINUX_SWAP) are meant to be swap partitions. (Warning: Solaris also uses this type. Be careful not to kill your Solaris partitions!! ๐ญ please I'm begging)
The blocks parameter is superfluous but it's been retained for backwards compatibility. (It specifies the desired size of the swap area in 1024-byte blocks. mkswap will use the entire partition or file if it is omitted. Specifying it is unwise โ a typo may destroy your disk. like. the whole disk. gone. ๐)
After creating the swap area, you need the swapon(8) command to start actually using it. Usually swap areas are listed in /etc/fstab so they can be taken into use at boot time by a swapon -a command in some boot script. slay, automation. โจ
โ ๏ธ WARNING โ ๏ธ
bestie this section is the "read it before you wreck it" section, pls don't skim ๐จ
The swap header does not touch the first block. A boot loader or disk label can be there, but that is not a recommended setup. The recommended setup is to use a separate partition for a Linux swap area. ๐
mkswap, like many others mkfs-like utils, erases the first partition block to make any previous filesystem invisible. bye bye old data ๐
However, mkswap refuses to erase the first block on a device with a disk label (SUN, BSD, ...). she said "not today" ๐
๐ OPTIONS ๐
-c,--checkโ 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. ๐-F,--fileโ Create a swap file with the appropriate file permissions and populated blocks on disk.-f,--forceโ 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,mkswapwill refuse to erase the first block on a device with a partition table.-q,--quietโ Suppress output and warning messages. ๐คซ-L,--labellabel โ Specify a label for the device, to allowswapon(8)by label. ๐ท๏ธ--lock[=mode]โ Use an exclusive BSD lock for the device or file that is operated upon. The optional argument mode can beyes(1),no(0), ornonblock. If the mode argument is omitted, it defaults toyes. This option overrides the environment variable$LOCK_BLOCK_DEVICE. The default is to not use any lock at all, but using a lock is recommended to avoid collisions withsystemd-udevd(8)or other tools. ๐-p,--pagesizesize โ Specify the page size (in bytes) to use. This option is usually unnecessary;mkswapreads the size from the kernel. ๐ง-U,--uuidUUID โ Specify the UUID to use. The default is to generate a UUID. The format of the UUID is a series of hex digits separated by hyphens, like this:"c1b9d5a2-f162-11cf-9ece-0020afc76f16". The UUID parameter may also be one of the following:clearโ clear the filesystem UUID ๐งผrandomโ generate a new randomly-generated UUID ๐ฒtimeโ generate a new time-based UUID โฐ
-e,--endiannessENDIANNESS โ Specify the ENDIANNESS to use, valid arguments arenative,littleorbig. The default isnative. ๐-o,--offsetoffset โ Specify the offset to write the swap area to.-s,--sizesize โ Specify the size of the created swap file in bytes and may be followed by a multiplicative suffix:KiB(=1024),MiB(=1024*1024), and so on forGiB,TiB,PiB,EiB,ZiBandYiB(the"iB"is optional, e.g.,"K"has the same meaning as"KiB"). If the file exists and is larger than size, it will be truncated to this size. This option only makes sense when used with--file. ๐-v,--swapversion 1โ Specify the swap-space version. (This option is currently pointless, as the old-v 0option has become obsolete and now only-v 1is supported. The kernel has not supported v0 swap-space format since2.5.22(June 2002). The new version v1 is supported since2.1.117(August 1998).) ๐ฐ๏ธ--verboseโ Verbose execution. With this optionmkswapwill output more details about detected problems during swap area set up. ๐ฃ๏ธ-h,--helpโ Display help text and exit. ๐-V,--versionโ Display version and exit. ๐
๐ ENVIRONMENT ๐
LIBBLKID_DEBUG=allโ enables libblkid debug output. ๐LOCK_BLOCK_DEVICE=<mode>โ use exclusive BSD lock. The mode is"1"or"0". See--lockfor more details. ๐
๐ NOTES ๐
The maximum useful size of a swap area depends on the architecture and the kernel version. iykyk.
The maximum number of the pages that is possible to address by swap area header is 4294967295 (32-bit unsigned int). The remaining space on the swap device is ignored. ๐
Presently, Linux allows 32 swap areas. The areas in use can be seen in the file /proc/swaps. ๐
mkswap refuses areas smaller than 10 pages. tiny swap? denied. ๐
If you don't know the page size that your machine uses, you can look it up with getconf PAGESIZE. โจ
Aside from mkswap --file, it is also possible to create the swapfile manually before initializing it with mkswap, e.g. using a command like
# dd if=/dev/zero of=swapfile bs=1MiB count=$((8*1024))
to create 8GiB swapfile. ๐
Since version 2.41, mkswap --file sets the nocow attribute for newly created files to support swapfiles on Btrfs. ๐ณ
In such a case, please read notes from swapon(8) about the swap file use restrictions (holes, preallocation and copy-on-write issues). ๐
๐ซ SEE ALSO ๐ซ
๐ REPORTING BUGS ๐
For bug reports, use the issue tracker <https://github.com/util-linux/util-linux/issues>. go tell them bestie, they wanna know ๐ซถ
๐ AVAILABILITY ๐
The mkswap command is part of the util-linux package which can be downloaded from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils/util-linux/>. ๐ฆ
and that's the whole page bestie!! ๐ฆ this one's from util-linux 2.42.4, dated 2026-09-21 โ swapon responsibly, and remember: a typo in blocks can eat your disk, so maybe just don't ๐โจ๐
๐ฆ where this page comes from
- arch rolling: util-linux 2.42.4-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause-UC AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND ISC AND LGPL-2.1-or-later AND LicenseRef-PublicDomain
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms