MKSWAP(8) Linux Programmer’s Manual MKSWAP(8) 名前 mkswap - Linux のスワップ領域を準備する 書式 mkswap [-c] [-vN] [-f] [-p PSZ] [-L label] device [size] 説明 mkswap は Linux のスワップ領域をデバイス上またはファイル上に準備する。 (スワップ領域を準備した後にこの領域の利用を開始するには、 swapon コマン ドを用いる必要がある。通常スワップ領域は /etc/fstab にリストされ、起 動 スクリプトに記述されている swapon -a コマンドによって、起動時から利用で きるようになっている。) 引き数 device は通常はディスクパーティション (/dev/hda4 や /dev/sdb7 の ようなもの) であるが、ファイルを指定することもできる。 Linux カーネルは パーティション ID を参照しないが、インストールスクリプトの多くでは、 パ ーティション形式が 16 進の 82 (LINUX_SWAP) となっているものをスワップパ ーティションとみなしている。 (警告: Solaris もこの形式を使う。 Solaris のパーティションを破壊しないように注意すること。) size パラメータは不要であるが、過去との互換性のために残してある。 (スワ ップ領域にしたいサイズを 1024 バイトブロック単位で指定する。このパラ メ ー タが省略されると、 mkswap はパーティション全体を用いる。このパラメー タは指定しないほうが賢い。タイプミスをするとディスクを壊してしまう。) PSZ 引き数は、用いるページサイズを指定する。ほとんどの場合は指定しな く て もよい (というか指定するのは賢くない) が、古い libc のあるバージョン はページサイズの値を間違えて返すことがあり、 mkswap の動作をおかしく し てしまうことがある。これに伴う症状として、 swapon が "no swap signature is found" といって失敗する。 PSZ に与える通常の値は 4096 または 8192 で ある。 Linux はスワップ領域として 2 つの形式を認識する。古い形式と新しい形式と である。これらは、スワップ領域先頭ページの末尾 10 バイトによって区別 さ れる。古い形式では ‘SWAP_SPACE’、新しい形式では ‘SWAPSPACE2’ がそれぞれ サインとなる。 古い形式では、先頭ページの残りの部分はビットマップであり、 1 ビットがス ワ ップ領域で利用できるそれぞれのページに対応する。先頭のページはこのビ ットマップを保持するので、先頭ビットは 0 である。また最後の 10 バイトは サインになっている。したがってページサイズを S とすれば、古い形式のスワ ップ領域は最大で 8*(S-10)-1 ページをスワップに用いること が で き る 。 S=4096 (i386 の値) ならば、利用できる領域の最大値は 133890048 バイト ( ほぼ 128 MiB) であり、残りの部分は無駄となる。 alpha と sparc64 で は S=8192 なので、最大値は 535560992 バイト (ほぼ 512 MiB) となる。 古 い形式では、このビットマップページの大部分を無駄にしていることになる 。なぜならマップ中のビット 0 は、不良ブロックかスワップ領域の境界後にあ る ブロックを示すためのものだからである。スワップ領域のサイズは簡単な計 算で求まる値に制限されるかわり、不良ブロックがあればリストするのが簡 単 に なっている。しかし不良ブロックがたくさんあるような領域をスワップにし たい人など誰もいないだろう (筆者は 1 つの不良ブロックでさえ許した く な い)。新しい形式のスワップ領域では、これはもっとしかるべく扱われている。 利用できるスワップ領域の最大値は、現在ではアーキテクチャ依存で あ る 。 i386, PPC, m68k, ARM では約 2GiB、 sparc では 1GiB、 mips では 512MiB, alpha では 128GiB, sparc64 では 3TiB である。 2.1.117 以前のカーネルでは、 1 ページあたり 1 バイトを割り当てていた が 、 現在では 2 バイトを割り当てている。したがって 2 GiB のスワップ領域に は 2 MiB のカーネルメモリが必要となる。 現時点では、 Linux は 32 個のスワップ領域を持つこと が で き る (Linux 2.4.10 より前は 8 個であった)。利用している領域は /proc/swaps ファイル で見ることができる (2.1.25 以降)。 mkswap では 10 ページより小さい領域を作ることはできない。 使っているマシンのページサイズがわからない場合は 、"cat /proc/cpuinfo" によって調べることができるかもしれない。 (できないかもしれない - このフ ァイルの内容はアーキテクチャとカーネルのバージョンに依存しているので。) ス ワップファイルを作成する場合は、 mkswap による初期化を行う前に、ファ イルを作成しておく必要がある。この目的には、以下のようなコマンドを用 い れば良い: # dd if=/dev/zero of=swapfile bs=1024 count=65536 スワップファイルには "hole" (未確保の領域) が存在してはならないことに注 意せよ (したがってファイルを作成する際に cp(1) を使ってはならない)。 オプション -c スワップ領域を作る前に、デバイスに対して不良ブロックのチェックを 行う。不良ブロックが見つかった場合は、そのカウント数を表示する。 -f 強制する。馬鹿なコマンドでも実行する。これを指定すると、ファイル またはパーティションの実際の大きさよりも大きなスワップファイルを 作る動作ができてしまう。 SPARC ではスワップ領域を強制的に作成 す る 。このオプションを付けないと、 mkswap は正しい SPARC のスーパ ーブロックを持ったデバイスには v0 のスワップを作成しない。パーテ ィションテーブルを消してしまう可能性があるからである。 -p PSZ 用いるページサイズを指定する。 -L label ラベルを指定し、そのラベルで swapon できるようにする。 (新しい形 式のスワップ領域のみ。) -v0 古い形式のスワップ領域を作成する。 -v1 新しい形式のスワップ領域を作成する。 -v オプションを省略して mkswap を実行すると、デフォルトでは新しい形式を 作 成 す る 。 し かし使用中のカーネルが 2.1.117 より古い場合 (あるいは PAGE_SIZE が 2048 より小さい場合) には、古い形式で作成する。新しい形 式 の ヘッダは、最初のブロックには書き込まない。したがってブートローダやデ ィスクラベルを置く場合にはこちらが望ましい。 2.0 と 2.2 のカーネルを 両 方用いる必要がある場合は、スワップ領域を作成する際には -v0 オプションを 用いること。 関連項目 fdisk(8), swapon(8) Linux 2.2.4 25 March 1999 MKSWAP(8)
MKSWAP(8) Linux Programmer’s Manual MKSWAP(8) NAME mkswap - set up a Linux swap area SYNOPSIS mkswap [-c] [-f] [-p PSZ] [-L label] [-U uuid] device [size] DESCRIPTION mkswap sets up a Linux swap area on a device or in a file. The device argument will usually be a disk partition (something like /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 parti- tions 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 compati- bility. (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. 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. WARNING The swap header does not touch the first block. A boot loader or disk label can be there, but it is not recommended setup. The recommended setup is to use a separate partition for a Linux swap area. mkswap like many others mkfs-like utils erases the first block to remove old on-disk filesystems. mkswap refuses to erase the first block on a device with a disk label (SUN, BSD, ...) or on whole disk (e.g. /dev/sda). 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. Without this option mkswap will refuse to erase the first block on a device with a partition table or on whole disk (e.g. /dec/sda). -p PSZ Specify the page size to use. -L label Specify a label, to allow swapon by label. (Only for new style swap areas.) -v0, -v1 Specify the swap space version. This option is deprecated and -v1 is supported only. The kernel has not supported v0 swap space format since 2.5.22. The new version v1 is supported since 2.1.117. -U uuid Specify the uuid to use. The default is to generate UUIDs. NOTES The maximum useful size of a swap area depends on the architecture and the kernel version. It is roughly 2GiB on i386, PPC, m68k, ARM, 1GiB on sparc, 512MiB on mips, 128GiB on alpha and 3TiB on sparc64. For ker- nels after 2.3.3 there is no such limitation. 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 ini- tializing 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). SEE ALSO fdisk(8), swapon(8) AVAILABILITY The mkswap command is part of the util-linux-ng package and is avail- able from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/. Linux 13 March 2009 MKSWAP(8)
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa