TUTORIAL TO ADD SWAP MEMORY ON YOUR VPS

codered26

Forum Expert
Here's a simple guide how to add memory swap in your vps server to cover the memory needed when you have a low ram vps


To add a memory swap on your VPS, you can follow these steps:

1. Check if your VPS has a swap partition: First, you need to check if your VPS already has a swap partition. Run the following command to view the current swap configuration:
๐Ÿ‘‡
sudo swapon --show

This command will display any active swap partitions. If it doesn't show any output, it means you don't have a swap partition set up yet.

2. Create a swap file: If your VPS doesn't have a swap partition, you can create a swap file instead. Use the following command to create a swap file with a desired size (e.g., 5GB):
๐Ÿ‘‡
sudo fallocate -l 5G /swapfile

This will create a 5GB swap file named /swapfile. You can adjust the size as per your requirements.

3. Set the correct permissions for the swap file: Change the permissions of the swap file to restrict access:
๐Ÿ‘‡

sudo chmod 600 /swapfile


4. Enable the swap file: Enable the swap file using the following command:
๐Ÿ‘‡
sudo mkswap /swapfile
sudo swapon /swapfile

This will format the swap file and enable it as a swap area.

5. Verify the swap setup: To verify if the swap file is active, use the command:
๐Ÿ‘‡

sudo swapon --show


It should now display the swap file as active.

6. Make the swap file permanent: To make the swap file persistent across reboots, you need to add an entry in the /etc/fstab file. Open the /etc/fstab file using a text editor:
๐Ÿ‘‡
sudo nano /etc/fstab

Add the following line at the end of the file:
๐Ÿ‘‡

/swapfile swap swap defaults 0 0


Save the file and exit the text editor.

That's it! You have successfully created a memory swap file on your VPS. The swap file will provide additional virtual memory in case your server's RAM usage exceeds capacity.


Note: To avoid further questions, This tutorial is for advanced members only with simple/basic knowledge in vps servers
 

About this Thread

  • 4
    Replies
  • 1K
    Views
  • 2
    Participants
Last reply from:
codered26

Trending Topics

Online now

Members online
1,065
Guests online
7,810
Total visitors
8,875

Forum statistics

Threads
2,358,043
Posts
29,399,625
Members
1,069,510
Latest member
LiaisonMaester
Back
Top