This article will help you to create swap space on your ubuntu system after installation.

How to Add Swap in Ubuntu

Follow the below steps to create and enable Swap memory on your Ubuntu system.

1. Check Current Swap

Before working make sure that the system has already swap enabled. If there is no swap, you will get the output header only.

2. Create Swap File

Let’s create a file to use for swapping in the system of the required size. Before making a file make sure you have enough free space on the disk. Generally, it recommends that the swap should be equal to double of installed physical memory. My Digital Ocean droplet has 2GB of memory. So creating the swapfile of 4GB in size. Then, make it to swap format and activate it on your system by running the following commands:

3. Make Swap Permanent

After running the above commands, Swap memory is added to your system and the operating system can use it when required. But after a reboot of the system swap will deactivate again. You can make it permanent by appending the following entry in /etc/fstab file. Edit /etc/fstab file in the editor: Append the below entry to the end of the file:

Save the file and close. Now Swap memory will remain activated after the system reboots.

4. Check System Swap Memory

You have successfully added swap memory to your system. Execute one of the below commands to view the current active swap memory on your system:

5. Update Swappiness Parameter

Now change the swappiness kernel parameter as per your requirement. It tells the system how often the system utilizes this swap area. Edit /etc/sysctl.conf file: Append the following configuration to the end of the file Now reload the sysctl configuration file

Conclusion

When a system runs out of memory, the operating system will begin to swap or page out memory pages to persistent storage such as a disk drive. When you have more free disk space, you can add additional swap space so your OS has an additional location to store temporary data when necessary. In this tutorial, you have learned to add Swap space on the Ubuntu systems.

How to Add Swap Space In Ubuntu 22 04  20 04   TecAdmin - 81How to Add Swap Space In Ubuntu 22 04  20 04   TecAdmin - 87How to Add Swap Space In Ubuntu 22 04  20 04   TecAdmin - 80