Imported upstream version 1.5
[manpages-zh.git] / raw / man8 / mkswap.8
blobe143704bde4a9d2b980b17bb54c40319ef4147e5
1 .\" Copyright 1998 Andries E. Brouwer (aeb@cwi.nl)
2 .\"
3 .\" May be distributed under the GNU General Public License
4 .\" Rewritten for 2.1.117, aeb, 981010.
5 .\"
6 .TH MKSWAP 8 "25 March 1999" "Linux 2.2.4" "Linux Programmer's Manual"
7 .SH NAME
8 mkswap \- set up a Linux swap area
9 .SH SYNOPSIS
10 .BI "mkswap [\-c] [\-v" N "] [\-f] [\-p " PSZ "] "device  " [" size "]"
11 .SH DESCRIPTION
12 .B mkswap
13 sets up a Linux swap area on a device or in a file.
15 (After creating the swap area, you need the
16 .B swapon
17 command to start using it. Usually swap areas are listed in
18 .I /etc/fstab
19 so that they can be taken into use at boot time by a
20 .B swapon -a
21 command in some boot script.)
23 The
24 .I device
25 argument will usually be a disk partition (something like
26 .I /dev/hda4
28 .IR /dev/sdb7 )
29 but can also be a file.
30 The Linux kernel does not look at partition Id's, but
31 many installation scripts will assume that partitions
32 of hex type 82 (LINUX_SWAP) are meant to be swap partitions.
33 (Warning: Solaris also uses this type. Be careful not to kill
34 your Solaris partitions.)
36 The
37 .I size
38 parameter is superfluous but retained for backwards compatibility.
39 (It specifies the desired size of the swap area in 1024-byte blocks.
40 .B mkswap
41 will use the entire partition or file if it is omitted.
42 Specifying it is unwise - a typo may destroy your disk.)
44 The
45 .I PSZ
46 parameter specifies the page size to use. It is almost always
47 unnecessary (even unwise) to specify it, but certain old libc
48 versions lie about the page size, so it is possible that
49 .B mkswap
50 gets it wrong. The symptom is that a subsequent
51 .B swapon
52 fails because no swap signature is found. Typical values for
53 .I PSZ
54 are 4096 or 8192.
56 Linux knows about two styles of swap areas, old style and new style.
57 The last 10 bytes of the first page of the swap area distinguishes
58 them: old style has `SWAP_SPACE', new style has `SWAPSPACE2' as
59 signature.
61 In the old style, the rest of this first page was a bit map,
62 with a 1 bit for each usable page of the swap area.
63 Since the first page holds this bit map, the first bit is 0.
64 Also, the last 10 bytes hold the signature. So, if the page
65 size is S, an old style swap area can describe at most
66 8*(S-10)-1 pages used for swapping.
67 With S=4096 (as on i386), the useful area is at most 133890048 bytes
68 (almost 128 MiB), and the rest is wasted.
69 On an alpha and sparc64, with S=8192, the useful area is at most
70 535560992 bytes (almost 512 MiB).
72 The old setup wastes most of this bitmap page, because zero bits
73 denote bad blocks or blocks past the end of the swap space,
74 and a simple integer suffices to indicate the size of the swap space,
75 while the bad blocks, if any, can simply be listed. Nobody wants
76 to use a swap space with hundreds of bad blocks. (I would not even
77 use a swap space with 1 bad block.)
78 In the new style swap area this is precisely what is done.
79 The maximum useful size of a swap area now depends on the architecture.
80 It is roughly 2GiB on i386, PPC, m68k, ARM, 1GiB on sparc, 512MiB on mips,
81 128GiB on alpha and 3TiB on sparc64.
83 Note that before 2.1.117 the kernel allocated one byte for each page,
84 while it now allocates two bytes, so that taking a swap area of 2 GiB
85 in use might require 2 MiB of kernel memory.
87 Presently, Linux allows 32 swap areas (this was 8 before Linux 2.4.10).
88 The areas in use can be seen in the file
89 .I /proc/swaps
90 (since 2.1.25).
92 .B mkswap
93 refuses areas smaller than 10 pages.
95 If you don't know the page size that your machine uses, you may be
96 able to look it up with "cat /proc/cpuinfo" (or you may not -
97 the contents of this file depend on architecture and kernel version).
99 To setup a swap file, it is necessary to create that file before
100 initializing it with
101 .B mkswap ,
102 e.g. using a command like
106 # dd if=/dev/zero of=swapfile bs=1024 count=65536
110 Note that a swap file must not contain any holes (so, using
111 .BR cp (1)
112 to create the file is not acceptable).
114 .SH OPTIONS
116 .B \-c
117 Check the device (if it is a block device) for bad blocks
118 before creating the swap area.
119 If any are found, the count is printed.
121 .B \-f
122 Force - go ahead even if the command is stupid.
123 This allows the creation of a swap area larger than the file
124 or partition it resides on.
125 On SPARC, force creation of the swap area.
126 Without this option
127 .B mkswap
128 will refuse to create a v0 swap on a device with a valid SPARC superblock,
129 as that probably means one is going to erase the partition table.
131 .BI "\-p " PSZ
132 Specify the page size to use.
134 .B \-v0
135 Create an old style swap area.
137 .B \-v1
138 Create a new style swap area.
141 If no \-v option is given,
142 .B mkswap
143 will default to new style, but use old style if the current kernel
144 is older than 2.1.117 (and also if PAGE_SIZE is less than 2048).
145 The new style header does not touch the first block, so may be
146 preferable, in case you have a boot loader or disk label there.
147 If you need to use both 2.0 and 2.2 kernels, use the \-v0 option
148 when creating the swapspace.
150 .SH "SEE ALSO"
151 .BR fdisk (8),
152 .BR swapon (8)