1MKSWAP(8)                    System Administration                   MKSWAP(8)
2
3
4

NAME

6       mkswap - set up a Linux swap area
7

SYNOPSIS

9       mkswap [options] device [size]
10

DESCRIPTION

12       mkswap sets up a Linux swap area on a device or in a file.
13
14       The device argument will usually be a disk partition (something like
15       /dev/sdb7) but can also be a file. The Linux kernel does not look at
16       partition IDs, but many installation scripts will assume that
17       partitions of hex type 82 (LINUX_SWAP) are meant to be swap partitions.
18       (Warning: Solaris also uses this type. Be careful not to kill your
19       Solaris partitions.)
20
21       The size parameter is superfluous but retained for backwards
22       compatibility. (It specifies the desired size of the swap area in
23       1024-byte blocks. mkswap will use the entire partition or file if it is
24       omitted. Specifying it is unwise - a typo may destroy your disk.)
25
26       After creating the swap area, you need the swapon(8) command to start
27       using it. Usually swap areas are listed in /etc/fstab so that they can
28       be taken into use at boot time by a swapon -a command in some boot
29       script.
30

WARNING

32       The swap header does not touch the first block. A boot loader or disk
33       label can be there, but it is not a recommended setup. The recommended
34       setup is to use a separate partition for a Linux swap area.
35
36       mkswap, like many others mkfs-like utils, erases the first partition
37       block to make any previous filesystem invisible.
38
39       However, mkswap refuses to erase the first block on a device with a
40       disk label (SUN, BSD, ...).
41

OPTIONS

43       -c, --check
44           Check the device (if it is a block device) for bad blocks before
45           creating the swap area. If any bad blocks are found, the count is
46           printed.
47
48       -f, --force
49           Go ahead even if the command is stupid. This allows the creation of
50           a swap area larger than the file or partition it resides on.
51
52           Also, without this option, mkswap will refuse to erase the first
53           block on a device with a partition table.
54
55       -q, --quiet
56           Suppress output and warning messages.
57
58       -L, --label label
59           Specify a label for the device, to allow swapon(8) by label.
60
61       --lock[=mode]
62           Use exclusive BSD lock for device or file it operates. The optional
63           argument mode can be yes, no (or 1 and 0) or nonblock. If the mode
64           argument is omitted, it defaults to yes. This option overwrites
65           environment variable $LOCK_BLOCK_DEVICE. The default is not to use
66           any lock at all, but it’s recommended to avoid collisions with
67           systemd-udevd(8) or other tools.
68
69       -p, --pagesize size
70           Specify the page size (in bytes) to use. This option is usually
71           unnecessary; mkswap reads the size from the kernel.
72
73       -U, --uuid UUID
74           Specify the UUID to use. The default is to generate a UUID. The
75           format of the UUID is a series of hex digits separated by hyphens,
76           like this: "c1b9d5a2-f162-11cf-9ece-0020afc76f16". The UUID
77           parameter may also be one of the following:
78
79           clear
80               clear the filesystem UUID
81
82           random
83               generate a new randomly-generated UUID
84
85           time
86               generate a new time-based UUID
87
88       -e, --endianness ENDIANNESS
89           Specify the ENDIANNESS to use, valid arguments are native, little
90           or big. The default is native.
91
92       -v, --swapversion 1
93           Specify the swap-space version. (This option is currently
94           pointless, as the old -v 0 option has become obsolete and now only
95           -v 1 is supported. The kernel has not supported v0 swap-space
96           format since 2.5.22 (June 2002). The new version v1 is supported
97           since 2.1.117 (August 1998).)
98
99       --verbose
100           Verbose execution. With this option mkswap will output more details
101           about detected problems during swap area set up.
102
103       -h, --help
104           Display help text and exit.
105
106       -V, --version
107           Print version and exit.
108

ENVIRONMENT

110       LIBBLKID_DEBUG=all
111           enables libblkid debug output.
112
113       LOCK_BLOCK_DEVICE=<mode>
114           use exclusive BSD lock. The mode is "1" or "0". See --lock for more
115           details.
116

NOTES

118       The maximum useful size of a swap area depends on the architecture and
119       the kernel version.
120
121       The maximum number of the pages that is possible to address by swap
122       area header is 4294967295 (32-bit unsigned int). The remaining space on
123       the swap device is ignored.
124
125       Presently, Linux allows 32 swap areas. The areas in use can be seen in
126       the file /proc/swaps.
127
128       mkswap refuses areas smaller than 10 pages.
129
130       If you don’t know the page size that your machine uses, you can look it
131       up with getconf PAGESIZE.
132
133       To set up a swap file, it is necessary to create that file before
134       initializing it with mkswap, e.g. using a command like
135
136           # dd if=/dev/zero of=swapfile bs=1MiB count=$((8*1024))
137
138       to create 8GiB swapfile.
139
140       Please read notes from swapon(8) about the swap file use restrictions
141       (holes, preallocation and copy-on-write issues).
142

SEE ALSO

144       fdisk(8), swapon(8)
145

REPORTING BUGS

147       For bug reports, use the issue tracker at
148       https://github.com/util-linux/util-linux/issues.
149

AVAILABILITY

151       The mkswap command is part of the util-linux package which can be
152       downloaded from Linux Kernel Archive
153       <https://www.kernel.org/pub/linux/utils/util-linux/>.
154
155
156
157util-linux 2.39.2                 2023-08-17                         MKSWAP(8)
Impressum