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