mkswap 中文man页面

系统
mkswap 在一个设备上或者在一个文件里创建一个linux交换区。

NAME

mkswap - 建立一个linux交换区  

总览

mkswap [-c] [-vN] [-f] device [size]  

描述

mkswap 在一个设备上或者在一个文件里创建一个linux交换区。

(该交换区创建后,必须使用 swapon 命令来启用它。通常交换区被列在 /etc/fstab 中,从而使得在启动时可通过某些启动脚本中的 swapon -a 命令来启用。)

参数 device 通常是一个磁盘分区(类似于 /dev/hda4 或者 /dev/sdb7 ),但也可以是一个文件。 Linux内核不会着眼于分区号,但是一些安装脚本会假定类型为 16进制的82(LINUX_SWAP)的分区意味着交换分区。

参数 size 是多余的,但为了向兼容性而被保留。(它指定期望的以1024 字节为单位的交换区大小。如果它未被指定, mkswap 将使用整个分区或者文件。错误地使用"-a"选项将会损坏您的磁盘。)

Linux能理解两种类型的交换区:旧类型和新类型。交换区第一页的最后 10个字节区分两种类型:旧类型以"SWAP_SPACE",新类型以"SWAPSPACE2" 作标识。

在旧类型里,第一页的其它部分是一个位图,每一位指出交换区中的可用页面。因为第一页保存位图,所以第一位为0。同样的,最后10位保存标识。所以,如果页面大小为S,旧类型交换区可以描述最多8*(S-10)-1 个可用于交换的页面。对于S=4096(象i386上),最大可用区域是 133890048字节(如果1 MB=2^20 bytes,则差不多为128 MB),而其他部分将被浪费。在alpha和sparc64上,S=8192,最大可用区域是535560992字节(与上述同样条件下,差不多为512 MB)。

因为零位表示坏的块或者超过交换区末尾的块,旧的设置浪费了大部分的位图页面,一个简单的整数就可以满足指出交换区大小的需要,而且如果有坏的块,也可以简单的列出来。没有人想使用有许多坏块的交换区(我甚至不会使用包含一个坏块的交换空间)。在新类型交换区正好是这样做的。现在交换区的最大可用数目取决于具体结构。大致来说,在i386, PPC, m68k, ARM上为2GB,在sparc上为1GB,在mips上为512MB,在alpha 上为128GB,在sparc64上为3TB。

注意在2.1.117内核之前,每一页分配一个字节,而现在为两个字节,所以为了获得2GB的可用交换区,可能需要2MB的核心内存。

目前,Linux允许8个交换区。这些正在使用的区域可从文件 /proc/swaps (从2.1.25起)中查到。

mkswap 不允许小于10个页面的区域。

如果不知道您的机器所用的页面大小,可以用"cat /proc/cpuinfo"来查看(或者不能查看 - 这个文件的内容取决于系统结构和内核版本)。

为了设置一个交换文件,需要在执行 mkswap , 前创建这个文件,例如,象如下命令:

# dd if=/dev/zero of=swapfile bs=1024 count=65536

注意一个交换文件必须不包括任何空洞(所以,不能使用 cp(1) 来创建该文件)。

选项

-c
在创建交换区之前检查设备(如果是块设备)的坏块。如果发现任何坏块,坏块的总数将被打印出来。
-f
强行向前执行,即使该命令是愚蠢的。该选项允许建立比所在的文件或者分区还大的交换区。在SPARC上,强行创建交换区。无该选项的 mkswap 将拒绝在包含有效的SPARC超级块的设备上创建vo交换区,因为那样可能意味着将删除分区表。
-v0
创建一个旧类型的交换区。
-v1
创建一个新类型的交换区。

如果未指定-v选项,而且交换区大小没有超过旧类型交换区的最大值,同时当前内核比2.1.117老(且PAGE_SIZE小于 2048), mkswap 将默认创建旧类型的交换区。万一您的引导分区或者磁盘卷标在第一块,新类型的头部将不接触那些部分,所以可能更好(如果同样交换区较小),

参考

fdisk(8), swapon(8)

#p#

NAME

mkswap - set up a Linux swap area  

SYNOPSIS

mkswap [-c] [-vN] [-f] [-p PSZ] device [size]  

DESCRIPTION

mkswap sets up a Linux swap area on a device or in a file.

(After creating the swap area, you need the swapon command to start using it. Usually swap areas are listed in /etc/fstab so that they can be taken into use at boot time by a swapon -a command in some boot script.)

The device argument will usually be a disk partition (something like /dev/hda4 or /dev/sdb7) but can also be a file. The Linux kernel does not look at partition Id's, but many installation scripts will assume that partitions of hex type 82 (LINUX_SWAP) are meant to be swap partitions. (Warning: Solaris also uses this type. Be careful not to kill your Solaris partitions.)

The size parameter is superfluous but retained for backwards compatibility. (It specifies the desired size of the swap area in 1024-byte blocks. mkswap will use the entire partition or file if it is omitted. Specifying it is unwise - a typo may destroy your disk.)

The PSZ parameter specifies the page size to use. It is almost always unnecessary (even unwise) to specify it, but certain old libc versions lie about the page size, so it is possible that mkswap gets it wrong. The symptom is that a subsequent swapon fails because no swap signature is found. Typical values for PSZ are 4096 or 8192.

Linux knows about two styles of swap areas, old style and new style. The last 10 bytes of the first page of the swap area distinguishes them: old style has `SWAP_SPACE', new style has `SWAPSPACE2' as signature.

In the old style, the rest of this first page was a bit map, with a 1 bit for each usable page of the swap area. Since the first page holds this bit map, the first bit is 0. Also, the last 10 bytes hold the signature. So, if the page size is S, an old style swap area can describe at most 8*(S-10)-1 pages used for swapping. With S=4096 (as on i386), the useful area is at most 133890048 bytes (almost 128 MiB), and the rest is wasted. On an alpha and sparc64, with S=8192, the useful area is at most 535560992 bytes (almost 512 MiB).

The old setup wastes most of this bitmap page, because zero bits denote bad blocks or blocks past the end of the swap space, and a simple integer suffices to indicate the size of the swap space, while the bad blocks, if any, can simply be listed. Nobody wants to use a swap space with hundreds of bad blocks. (I would not even use a swap space with 1 bad block.) In the new style swap area this is precisely what is done. The maximum useful size of a swap area now depends on the architecture. It is roughly 2GiB on i386, PPC, m68k, ARM, 1GiB on sparc, 512MiB on mips, 128GiB on alpha and 3TiB on sparc64.

Note that before 2.1.117 the kernel allocated one byte for each page, while it now allocates two bytes, so that taking a swap area of 2 GiB in use might require 2 MiB of kernel memory.

Presently, Linux allows 32 swap areas (this was 8 before Linux 2.4.10). The areas in use can be seen in the file /proc/swaps (since 2.1.25).

mkswap refuses areas smaller than 10 pages.

If you don't know the page size that your machine uses, you may be able to look it up with "cat /proc/cpuinfo" (or you may not - the contents of this file depend on architecture and kernel version).

To setup a swap file, it is necessary to create that file before initializing it with mkswap , e.g. using a command like

# dd if=/dev/zero of=swapfile bs=1024 count=65536

Note that a swap file must not contain any holes (so, using cp(1) to create the file is not acceptable).

OPTIONS

-c
Check the device (if it is a block device) for bad blocks before creating the swap area. If any are found, the count is printed.
-f
Force - go ahead even if the command is stupid. This allows the creation of a swap area larger than the file or partition it resides on. On SPARC, force creation of the swap area. Without this option mkswap will refuse to create a v0 swap on a device with a valid SPARC superblock, as that probably means one is going to erase the partition table.
-p PSZ
Specify the page size to use.
-v0
Create an old style swap area.
-v1
Create a new style swap area.

If no -v option is given, mkswap will default to new style, but use old style if the current kernel is older than 2.1.117 (and also if PAGE_SIZE is less than 2048). The new style header does not touch the first block, so may be preferable, in case you have a boot loader or disk label there. If you need to use both 2.0 and 2.2 kernels, use the -v0 option when creating the swapspace.

SEE ALSO

fdisk(8), swapon(8)

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-15 10:21:09

man中文man

2011-08-24 16:48:36

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-11-01 13:46:50

中文mantac

2011-08-25 16:55:26

gets中文man

2011-08-25 15:49:02

freopen中文man

2011-08-25 16:00:56

fflush中文man

2011-08-25 16:08:55

fsetpos中文man

2011-08-25 15:33:18

exit中文man

2011-08-25 10:55:37

services中文man

2011-08-25 09:35:26

units中文man

2011-08-24 13:57:35

DECLARE中文man

2011-08-11 15:28:43

ali中文man

2011-08-23 17:24:11

userdel中文man

2011-08-23 17:33:22

rdev中文man

2011-08-23 18:05:21

ABORT中文man

2011-08-18 19:15:25

group中文man

2011-08-23 10:17:54

bdflush中文man

2011-08-23 10:48:03

exportfs中文man
点赞
收藏

51CTO技术栈公众号