]> git.ipfire.org Git - thirdparty/util-linux.git/blame - disk-utils/mkswap.8
Imported from util-linux-2.9v tarball.
[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
KZ
4.\" Rewritten for 2.1.117, aeb, 981010.
5.\"
7eda085c 6.TH MKSWAP 8 "25 March 1999" "Linux 2.2.4" "Linux Programmer's Manual"
6dbe3af9 7.SH NAME
726f69e2 8mkswap \- set up a Linux swap area
6dbe3af9 9.SH SYNOPSIS
5c36a0eb 10.BI "mkswap [\-c] [\-v" N "] [\-f] " device " [" size "]"
6dbe3af9
KZ
11.SH DESCRIPTION
12.B mkswap
726f69e2 13sets up a Linux swap area on a device or in a file.
6dbe3af9 14
5c36a0eb
KZ
15(After creating the swap area, you need the
16.B swapon
17command to start using it. Usually swap areas are listed in
18.I /etc/fstab
19so that they can be taken into use at boot time by a
20.B swapon -a
21command in some boot script.)
22
6dbe3af9
KZ
23The
24.I device
5c36a0eb
KZ
25argument will usually be a disk partition (something like
26.I /dev/hda4
27or
28.IR /dev/sdb7 )
29but can also be a file.
30The Linux kernel does not look at partition Id's, but
31many installation scripts will assume that partitions
32of hex type 82 (LINUX_SWAP) are meant to be swap partitions.
6dbe3af9
KZ
33
34The
5c36a0eb
KZ
35.I size
36parameter is superfluous but retained for backwards compatibility.
37(It specifies the desired size of the swap area in 1024-byte blocks.
726f69e2 38.B mkswap
7eda085c
KZ
39will use the entire partition or file if it is omitted.
40Specifying it is unwise - a typo may destroy your disk.)
726f69e2 41
5c36a0eb
KZ
42Linux knows about two styles of swap areas, old style and new style.
43The last 10 bytes of the first page of the swap area distinguishes
44them: old style has `SWAP_SPACE', new style has `SWAPSPACE2' as
45signature.
6dbe3af9 46
5c36a0eb
KZ
47In the old style, the rest of this first page was a bit map,
48with a 1 bit for each usable page of the swap area.
49Since the first page holds this bit map, the first bit is 0.
50Also, the last 10 bytes hold the signature. So, if the page
51size is S, an old style swap area can describe at most
528*(S-10)-1 pages used for swapping.
53With S=4096 (as on i386), the useful area is at most 133890048 bytes
54(almost 128 MB if you believe in 1 MB=2^20 bytes), and the rest is wasted.
55On an alpha and sparc64, with S=8192, the useful area is at most
56535560992 bytes (almost 512 MB with the same proviso).
6dbe3af9 57
5c36a0eb
KZ
58The old setup wastes most of this bitmap page, because zero bits
59denote bad blocks or blocks past the end of the swap space,
60and a simple integer suffices to indicate the size of the swap space,
61while the bad blocks, if any, can simply be listed. Nobody wants
62to use a swap space with hundreds of bad blocks. (I would not even
63use a swap space with 1 bad block.)
64In the new style swap area this is precisely what is done.
7eda085c
KZ
65The maximum useful size of a swap area now depends on the architecture.
66It is roughly 2GB on i386, PPC, m68k, ARM, 1GB on sparc, 512MB on mips,
67128GB on alpha and 3TB on sparc64.
726f69e2 68
5c36a0eb
KZ
69Note that before 2.1.117 the kernel allocated one byte for each page,
70while it now allocates two bytes, so that taking a swap area of 2 GB
71in use might require 2 MB of kernel memory.
726f69e2 72
5c36a0eb
KZ
73Presently, Linux allows 8 swap areas. The areas in use can be seen
74in the file
75.I /proc/swaps
76(since 2.1.25).
726f69e2 77
5c36a0eb
KZ
78.B mkswap
79refuses areas smaller than 10 pages.
726f69e2 80
5c36a0eb
KZ
81If you don't know the page size that your machine uses, you may be
82able to look it up with "cat /proc/cpuinfo" (or you may not -
83the contents of this file depend on architecture and kernel version).
726f69e2
KZ
84
85To setup a swap file, it is necessary to create that file before
86running
5c36a0eb
KZ
87.B mkswap ,
88e.g. using a command like
6dbe3af9
KZ
89
90.nf
91.RS
5c36a0eb 92# dd if=/dev/zero of=swapfile bs=1024 count=65536
6dbe3af9
KZ
93.RE
94.fi
95
726f69e2 96Note that a swap file must not contain any holes (so, using
6dbe3af9
KZ
97.BR cp (1)
98to create the file is not acceptable).
99
100.SH OPTIONS
101.TP
102.B \-c
5c36a0eb
KZ
103Check the device (if it is a block device) for bad blocks
104before creating the swap area.
105If any are found, the count is printed.
106.TP
107.B \-f
7eda085c
KZ
108Force - go ahead even if the command is stupid.
109This allows the creation of a swap area larger than the file
110or partition it resides on.
5c36a0eb
KZ
111On SPARC, force creation of the swap area.
112Without this option
113.B mkswap
114will refuse to create a v0 swap on a device with a valid SPARC superblock,
115as that probably means one is going to erase the partition table.
116.TP
117.B \-v0
118Create an old style swap area.
119.TP
120.B \-v1
121Create a new style swap area.
122
123.LP
124If no \-v option is given,
125.B mkswap
126will default to old style if the size of the swap area does not
127exceed the maximum size of an old style swap area, and also if
128the current kernel is older than 2.1.117 (and also if PAGE_SIZE
129is less than 2048).
130The new style header does not touch the first block, so may be
131preferable (also if the swap area is small), in case you have
132a boot loader or disk label there.
133
6dbe3af9 134.SH "SEE ALSO"
5c36a0eb
KZ
135.BR fdisk (8),
136.BR swapon (8)