Linux "mkswap" Command Line Options and Examples
set up a Linux swap area

mkswap sets up a Linux swap area on a device or in a file. The device argument will usually be a disk partition (something like /dev/sdb7) but can also be a file. The Linux kernel does not look at partition IDs, but many installation scripts will assume that partitions of hex type 82 (LINUX_SWAP) are meant to be swap partitions.


Usage:

mkswap [options] device [size]






Command Line Options:

-c
Check the device (if it is a block device) for bad blocks before creating the swap area. If any bad blocks are found, thecount is printed.
mkswap -c ...
-f
Go ahead even if the command is stupid. This allows the creation of a swap area larger than the file or partition it resideson.Also, without this option, mkswap will refuse to erase the first block on a device with a partition table.
mkswap -f ...
-L
Specify a label for the device, to allow swapon by label.
mkswap -L ...
-p
Specify the page size (in bytes) to use. This option is usually unnecessary; mkswap reads the size from the kernel.
mkswap -p ...
-U
Specify the UUID to use. The default is to generate a UUID.
mkswap -U ...
-v
Specify the swap-space version. (This option is currently pointless, as the old -v 0 option has become obsolete and now only
mkswap -v ...
-h
Display help text and exit.
mkswap -h ...
-V
Display version information and exit.NOTESThe maximum useful size of a swap area depends on the architecture and the kernel version.The maximum number of the pages that is possible to address by swap area header is 4294967295 (UINT_MAX). The remaining space on theswap device is ignored.Presently, Linux allows 32 swap areas. The areas in use can be seen in the file /proc/swapsmkswap refuses areas smaller than 10 pages.If you don't know the page size that your machine uses, you may be able to look it up with "cat /proc/cpuinfo" (or you may not – thecontents of this file depend on architecture and kernel version).To set up a swap file, it is necessary to create that file before initializing it with mkswap, e.g. using a command like# fallocate --length 8GiB swapfileNote that a swap file must not contain any holes. Using cp(1) to create the file is not acceptable. Neither is use of fallocate(1)on file systems that support preallocated files, such as XFS or ext4, or on copy-on-write filesystems like btrfs. It is recommendedto use dd(1) and /dev/zero in these cases. Please read notes from swapon(8) before adding a swap file to copy-on-write filesystems.ENVIRONMENTLIBBLKID_DEBUG=allenables libblkid debug output.
mkswap -V ...