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 Section 17.13, “Encrypting Swap”.
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 Section 17.2, “Adding Disks” while Section 2.6.1, “Designing the Partition Layout” 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 Chapter 8, Configuring the FreeBSD Kernel for information about building a custom kernel.
X
and LaterCreate 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
and EarlierCreate 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 Section 17.9, “Memory Disks” for more information about memory devices.
#
mdconfig -a -t vnode -f
/usr/swap0
-u0
&& swapon /dev/md0
All FreeBSD documents are available for download at https://download.freebsd.org/ftp/doc/
Questions that are not answered by the
documentation may be
sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.