]>
Commit | Line | Data |
---|---|---|
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 | 8 | mkswap \- 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 | 13 | sets 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 | |
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.) | |
22 | ||
6dbe3af9 KZ |
23 | The |
24 | .I device | |
5c36a0eb KZ |
25 | argument will usually be a disk partition (something like |
26 | .I /dev/hda4 | |
27 | or | |
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. | |
6dbe3af9 KZ |
33 | |
34 | The | |
5c36a0eb KZ |
35 | .I size |
36 | parameter 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 |
39 | will use the entire partition or file if it is omitted. |
40 | Specifying it is unwise - a typo may destroy your disk.) | |
726f69e2 | 41 | |
5c36a0eb KZ |
42 | Linux knows about two styles of swap areas, old style and new style. |
43 | The last 10 bytes of the first page of the swap area distinguishes | |
44 | them: old style has `SWAP_SPACE', new style has `SWAPSPACE2' as | |
45 | signature. | |
6dbe3af9 | 46 | |
5c36a0eb KZ |
47 | In the old style, the rest of this first page was a bit map, |
48 | with a 1 bit for each usable page of the swap area. | |
49 | Since the first page holds this bit map, the first bit is 0. | |
50 | Also, the last 10 bytes hold the signature. So, if the page | |
51 | size is S, an old style swap area can describe at most | |
52 | 8*(S-10)-1 pages used for swapping. | |
53 | With 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. | |
55 | On an alpha and sparc64, with S=8192, the useful area is at most | |
56 | 535560992 bytes (almost 512 MB with the same proviso). | |
6dbe3af9 | 57 | |
5c36a0eb KZ |
58 | The old setup wastes most of this bitmap page, because zero bits |
59 | denote bad blocks or blocks past the end of the swap space, | |
60 | and a simple integer suffices to indicate the size of the swap space, | |
61 | while the bad blocks, if any, can simply be listed. Nobody wants | |
62 | to use a swap space with hundreds of bad blocks. (I would not even | |
63 | use a swap space with 1 bad block.) | |
64 | In the new style swap area this is precisely what is done. | |
7eda085c KZ |
65 | The maximum useful size of a swap area now depends on the architecture. |
66 | It is roughly 2GB on i386, PPC, m68k, ARM, 1GB on sparc, 512MB on mips, | |
67 | 128GB on alpha and 3TB on sparc64. | |
726f69e2 | 68 | |
5c36a0eb KZ |
69 | Note that before 2.1.117 the kernel allocated one byte for each page, |
70 | while it now allocates two bytes, so that taking a swap area of 2 GB | |
71 | in use might require 2 MB of kernel memory. | |
726f69e2 | 72 | |
5c36a0eb KZ |
73 | Presently, Linux allows 8 swap areas. The areas in use can be seen |
74 | in the file | |
75 | .I /proc/swaps | |
76 | (since 2.1.25). | |
726f69e2 | 77 | |
5c36a0eb KZ |
78 | .B mkswap |
79 | refuses areas smaller than 10 pages. | |
726f69e2 | 80 | |
5c36a0eb KZ |
81 | If you don't know the page size that your machine uses, you may be |
82 | able to look it up with "cat /proc/cpuinfo" (or you may not - | |
83 | the contents of this file depend on architecture and kernel version). | |
726f69e2 KZ |
84 | |
85 | To setup a swap file, it is necessary to create that file before | |
86 | running | |
5c36a0eb KZ |
87 | .B mkswap , |
88 | e.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 | 96 | Note that a swap file must not contain any holes (so, using |
6dbe3af9 KZ |
97 | .BR cp (1) |
98 | to create the file is not acceptable). | |
99 | ||
100 | .SH OPTIONS | |
101 | .TP | |
102 | .B \-c | |
5c36a0eb KZ |
103 | Check the device (if it is a block device) for bad blocks |
104 | before creating the swap area. | |
105 | If any are found, the count is printed. | |
106 | .TP | |
107 | .B \-f | |
7eda085c KZ |
108 | Force - go ahead even if the command is stupid. |
109 | This allows the creation of a swap area larger than the file | |
110 | or partition it resides on. | |
5c36a0eb KZ |
111 | On SPARC, force creation of the swap area. |
112 | Without this option | |
113 | .B mkswap | |
114 | will refuse to create a v0 swap on a device with a valid SPARC superblock, | |
115 | as that probably means one is going to erase the partition table. | |
116 | .TP | |
117 | .B \-v0 | |
118 | Create an old style swap area. | |
119 | .TP | |
120 | .B \-v1 | |
121 | Create a new style swap area. | |
122 | ||
123 | .LP | |
124 | If no \-v option is given, | |
125 | .B mkswap | |
126 | will default to old style if the size of the swap area does not | |
127 | exceed the maximum size of an old style swap area, and also if | |
128 | the current kernel is older than 2.1.117 (and also if PAGE_SIZE | |
129 | is less than 2048). | |
130 | The new style header does not touch the first block, so may be | |
131 | preferable (also if the swap area is small), in case you have | |
132 | a boot loader or disk label there. | |
133 | ||
6dbe3af9 | 134 | .SH "SEE ALSO" |
5c36a0eb KZ |
135 | .BR fdisk (8), |
136 | .BR swapon (8) |