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 Section17.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 Section17.2, “Adding Disks” while Section2.6.1, “Designing the Partition Layout” discusses partition layouts and swap partition size considerations.
swapon to add a swap partition to
the system. For example:
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
To automatically add this swap partition on boot, add an
/dev/ada1s1bnone swap sw 0 0
These examples create a 64M swap file called
/usr/swap0 instead of using a
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 Chapter8, Configuring the FreeBSD Kernel for information about building a custom kernel.
Create the swap file:
dd if=/dev/zero of=
Set the proper permissions on the new file:
Inform the system about the swap file by adding a line to
md99 none swap sw,file=/usr/swap0,late 0 0
The md(4) device
md99is 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):
Create the swap file,
dd if=/dev/zero of=
Set the proper permissions on
Enable the swap file in
/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 Section17.9, “Memory Disks” for more information about memory devices.
mdconfig -a -t vnode -f
0&& swapon /dev/md