
Swap space extends the capacity of your system's memory to improve performance when the RAM is full. During a memory shortage, your server stores inactive processes to the swap memory to run your system smoothly. Swapping processes prevents system shutdowns and crashes, especially when running multiple applications.
This article explains how to add a swap memory on FreeBSD 14.0.
Before you begin:
Before adding a swap memory, verify if there is any existing swap memory on the system by running the following command.
Output:
The above command displays an empty swap information.
You can create swap memory using:
Create a new swap file.
The above command creates a new Swapfile with 2 GB (bs=1M count=2048).
Create a new memory block device that points to the file.
Output:
The above command creates a memory block device associated with the /swapfile file and assigns it to the /dev/md0 device.
Enable the memory block device as a swap.
The above command activates the Swapfile's block device as swap memory.
Vultr Block Storage devices attached to your server use the vtbd naming scheme where the first block device is vtbd1 and any additional devices use incremented values such as vtbd2 for a second device. Follow the steps below to create swap memory using the Vultr Block Storage device attached to your server.
Initialize the block storage device attached to your server with a GPT partition table.
Output:
Add a new swap0 partition to the device and use the partition as a swap space.
Output:
Format and enable the swap partition:
Automatic mounting enables the server to mount the swap memory at boot. Follow the steps below to enable automatic mounting of your swap memory created from a Swapfile or a Vultr Block Storage device.
Modify the /etc/fstab file to include your Swapfile's block device.
Output:
Modify the /etc/fstab file to include your Vultr Block Storage device path.
Output:
Follow the steps below to ensure the swap memory is actively swapping processes.
View the available swap space.
Output:
View the swap memory usage using the top utility.
Output:
Swap memory actively swaps processes and includes 2048 free memory based on the above top output.
Follow the steps below when detaching swap memory from your server.
Disable the swap device.
Delete the memory block device.
Delete the swap file.
Remove the entry from /etc/fstab to disable automatic mounting.
Disable the swap partition.
Remove the swap partition entry from /etc/fstab.
In this article, you have added a swap memory on a FreeBSD 14.0 to allow your system to swap processes. You've learned to use a Swapfile or a Vultr Block Storage volume to extend your system's memory. For more information, visit the FreeBSD swap documentation.
0 Comments
Be the first to comment and share your perspective with the community.