]> git.ipfire.org Git - thirdparty/util-linux.git/blame - disk-utils/mkswap.8
col: use size_t when dealing with numbers that buffer sizes
[thirdparty/util-linux.git] / disk-utils / mkswap.8
CommitLineData
5c36a0eb
KZ
1.\" Copyright 1998 Andries E. Brouwer (aeb@cwi.nl)
2.\"
6dbe3af9 3.\" May be distributed under the GNU General Public License
5c36a0eb 4.\"
232dc924 5.TH MKSWAP 8 "March 2009" "util-linux" "System Administration"
6dbe3af9 6.SH NAME
726f69e2 7mkswap \- set up a Linux swap area
6dbe3af9 8.SH SYNOPSIS
e584ccb8 9.B mkswap
f49ccec2 10[options]
449a215f
BS
11.I device
12.RI [ size ]
6dbe3af9
KZ
13.SH DESCRIPTION
14.B mkswap
726f69e2 15sets up a Linux swap area on a device or in a file.
6dbe3af9
KZ
16
17The
18.I device
5c36a0eb 19argument will usually be a disk partition (something like
5c36a0eb
KZ
20.IR /dev/sdb7 )
21but can also be a file.
83ff3782 22The Linux kernel does not look at partition IDs, but
5c36a0eb
KZ
23many installation scripts will assume that partitions
24of hex type 82 (LINUX_SWAP) are meant to be swap partitions.
83ff3782 25(\fBWarning: Solaris also uses this type. Be careful not to kill
d10056b3 26your Solaris partitions.\fP)
6dbe3af9
KZ
27
28The
5c36a0eb
KZ
29.I size
30parameter is superfluous but retained for backwards compatibility.
31(It specifies the desired size of the swap area in 1024-byte blocks.
726f69e2 32.B mkswap
7eda085c 33will use the entire partition or file if it is omitted.
96979754 34Specifying it is unwise \(en a typo may destroy your disk.)
726f69e2 35
d10056b3
KZ
36After creating the swap area, you need the
37.B swapon
83ff3782 38command to start using it. Usually swap areas are listed in
d10056b3
KZ
39.I /etc/fstab
40so that they can be taken into use at boot time by a
96979754 41.B swapon \-a
d10056b3
KZ
42command in some boot script.
43
44.SH WARNING
83ff3782
BS
45The swap header does not touch the first block. A boot loader or disk label
46can be there, but it is not a recommended setup. The recommended setup is to
d10056b3
KZ
47use a separate partition for a Linux swap area.
48
449a215f
BS
49.BR mkswap ,
50like many others mkfs-like utils,
51.B erases the first partition block to make any previous filesystem invisible.
d10056b3 52
449a215f 53However,
d10056b3
KZ
54.B mkswap
55refuses to erase the first block on a device with a disk
96979754 56label (SUN, BSD, \&...\&).
d10056b3
KZ
57
58.SH OPTIONS
59.TP
17945af6 60.BR \-c , " \-\-check"
d10056b3
KZ
61Check the device (if it is a block device) for bad blocks
62before creating the swap area.
449a215f 63If any bad blocks are found, the count is printed.
d10056b3 64.TP
17945af6 65.BR \-f , " \-\-force"
449a215f 66Go ahead even if the command is stupid.
d10056b3
KZ
67This allows the creation of a swap area larger than the file
68or partition it resides on.
69
449a215f 70Also, without this option,
d10056b3 71.B mkswap
c1f1b301 72will refuse to erase the first block on a device with a partition table.
83ff3782 73.TP
449a215f
BS
74.BR \-L , " \-\-label " \fIlabel\fR
75Specify a \fIlabel\fR for the device, to allow
83ff3782
BS
76.B swapon
77by label.
d10056b3 78.TP
b8671fe7
KZ
79\fB\-\-lock\fR[=\fImode\fR]
80Use exclusive BSD lock for device or file it operates. The optional argument
81\fImode\fP can be \fByes\fR, \fBno\fR (or 1 and 0) or \fBnonblock\fR. If the \fImode\fR
82argument is omitted, it defaults to \fB"yes"\fR. This option overwrites
83environment variable \fB$LOCK_BLOCK_DEVICE\fR. The default is not to use any
84lock at all, but it's recommended to avoid collisions with udevd or other
85tools.
86.TP
449a215f
BS
87.BR \-p , " \-\-pagesize " \fIsize\fR
88Specify the page \fIsize\fR (in bytes) to use. This option is usually unnecessary;
c4c20b3a 89.B mkswap
83ff3782 90reads the size from the kernel.
d10056b3 91.TP
449a215f
BS
92.BR \-U , " \-\-uuid " \fIUUID\fR
93Specify the \fIUUID\fR to use. The default is to generate a UUID.
d10056b3 94.TP
449a215f
BS
95.BR \-v , " \-\-swapversion 1"
96Specify the swap-space version. (This option is currently pointless, as the old
97.B \-v 0
98option has become obsolete and now only
99.B \-v 1
100is supported.
101The kernel has not supported v0 swap-space format since 2.5.22 (June 2002).
102The new version v1 is supported since 2.1.117 (August 1998).)
17945af6 103.TP
701f0385
KZ
104\fB\-\-verbose\fR
105Verbose execution. With this option
106.B mkswap
107will output more details about detected problems during swap area set up.
108.TP
17945af6 109.BR \-h , " \-\-help"
449a215f
BS
110Display help text and exit.
111.TP
112.BR \-V , " \-\-version"
113Display version information and exit.
ca3ea756 114
67e63c12
MK
115.SH ENVIRONMENT
116.IP LIBBLKID_DEBUG=all
117enables libblkid debug output.
b8671fe7
KZ
118.IP LOCK_BLOCK_DEVICE=<mode>
119use exclusive BSD lock. The mode is "1" or "0". See \fB\-\-lock\fR for more details.
67e63c12 120
d10056b3 121.SH NOTES
ca3ea756
KZ
122The maximum useful size of a swap area depends on the architecture and
123the kernel version.
726f69e2 124
f1477c4b 125The maximum number of the pages that is possible to address by swap area header
f91c21cc 126is 4294967295 (32-bit unsigned int). The remaining space on the swap device is ignored.
f1477c4b 127
d9ba898a 128Presently, Linux allows 32 swap areas.
95f1bdee 129The areas in use can be seen in the file
5c36a0eb 130.I /proc/swaps
726f69e2 131
5c36a0eb
KZ
132.B mkswap
133refuses areas smaller than 10 pages.
726f69e2 134
5c36a0eb 135If you don't know the page size that your machine uses, you may be
96979754 136able to look it up with "cat /proc/cpuinfo" (or you may not \(en
5c36a0eb 137the contents of this file depend on architecture and kernel version).
726f69e2 138
83ff3782 139To set up a swap file, it is necessary to create that file before
22853e4a 140initializing it with
e584ccb8 141.BR mkswap ,
96979754 142e.g.\& using a command like
6dbe3af9
KZ
143
144.nf
145.RS
4d09682b 146# dd if=/dev/zero of=swapfile bs=1MiB count=$((8*1024))
6dbe3af9
KZ
147.RE
148.fi
149
4d09682b
KZ
150to create 8GiB swapfile.
151
eebfa469 152Please read notes from
55034ed0 153.BR swapon (8)
1895c76f
KZ
154about
155.B the swap file use restrictions
156(holes, preallocation and copy-on-write issues).
6dbe3af9 157
5a829806 158.SH SEE ALSO
5c36a0eb
KZ
159.BR fdisk (8),
160.BR swapon (8)
86d62711 161.SH AVAILABILITY
601d12fb 162The mkswap command is part of the util-linux package and is available from
d673b74e 163https://www.kernel.org/pub/linux/utils/util-linux/.