Sometimes a system requires more swap space. This section describes two methods to increase swap space: adding swap to an existing partition or new hard drive, and creating a swap file on an existing partition.
For information on how to encrypt swap space, which options exist, and why it should be done, refer to 節 17.13, “交換空間加密”.
Adding a new hard drive for swap gives better performance than using a partition on an existing drive. Setting up partitions and hard drives is explained in 節 17.2, “加入磁碟” while 節 2.6.1, “規劃分割區配置” discusses partition layouts and swap partition size considerations.
Use swapon
to add a swap partition to
the system. For example:
#
swapon /dev/ada1s1b
It is possible to use any partition not currently
mounted, even if it already contains data. Using
swapon
on a partition that contains data
will overwrite and destroy that data. Make sure that the
partition to be added as swap is really the intended
partition before running swapon
.
To automatically add this swap partition on boot, add an
entry to /etc/fstab
:
/dev/ada1s1b
none swap sw 0 0
See fstab(5) for an explanation of the entries in
/etc/fstab
. More information about
swapon
can be found in
swapon(8).
These examples create a 64M swap file called
/usr/swap0
instead of using a
partition.
Using swap files requires that the module needed by md(4) has either been built into the kernel or has been loaded before swap is enabled. See 章 8, 設定 FreeBSD 核心 for information about building a custom kernel.
X
及以後版本Create the swap file:
#
dd if=/dev/zero of=/usr/swap0
bs=1m count=64
Set the proper permissions on the new file:
#
chmod 0600 /usr/swap0
Inform the system about the swap file by adding a
line to /etc/fstab
:
md99 none swap sw,file=/usr/swap0,late 0 0
The md(4) device md99
is
used, leaving lower device numbers available for
interactive use.
Swap space will be added on system startup. To add swap space immediately, use swapon(8):
#
swapon -aL
X
及先前版本Create the swap file,
/usr/swap0
:
#
dd if=/dev/zero of=/usr/swap0
bs=1m count=64
Set the proper permissions on
/usr/swap0
:
#
chmod 0600 /usr/swap0
Enable the swap file in
/etc/rc.conf
:
swapfile="/usr/swap0
" # Set to name of swap file
Swap space will be added on system startup. To enable the swap file immediately, specify a free memory device. Refer to 節 17.9, “記憶體磁碟” for more information about memory devices.
#
mdconfig -a -t vnode -f /usr/swap0
-u 0
&& swapon /dev/md0
本文及其他文件,可由此下載: ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/。
若有 FreeBSD 方面疑問,請先閱讀
FreeBSD 相關文件,如不能解決的話,再洽詢
<questions@FreeBSD.org>。
關於本文件的問題,請洽詢
<doc@FreeBSD.org>。