How to Add Swap to a Linux Instance on AWS/EC2 [ Easy Guide ]
How to Add Swap space is useful for systems with limited memory (RAM). If your system is always running out of memory and you don’t want to increase the server’s RAM, enabling swap in your system may be helpful. Although swap is far slower than physical memory, the operating system employs it in the event that the system runs out of memory. Visit this page to learn more about how swaps operate.
How to Add Swap
This article will guide you through the process of enabling a swap file system in a running instance. In Amazon ec2 Linux instances, there are two ways to add swap. Although this article was tested on CentOS 6.9, it should work on other Linux systems as well.
Enable Swap Using A File
This method is useful if we don’t want to add additional discs to our systems. We just create a file in our present file system with the type swap, which can then be utilized as a swap in our system. To construct and enable swap on our system, use the instructions below.
bs=1M count=4096 implies it will create a swap file of 4 GB. You can alter this as needed. By using the “free -m” command after enabling swap, we can verify that our system has swap enabled.
Simply modify the /etc/fstab file and add the following entry at the end to enable it on system boot. After adding the swap entry to my fstab file, it looks like this.
Enable Swap Using Additional Disc
If you don’t have enough space on the system’s current discs, this option is useful. In order to use this option, we must first add additional disc space to our system. The new disc is mounted
as /dev/xvdd in my case (It may change in your case)
Simply edit the
/etc/fstab file and add the following entry at the end to enable it on system boot. After you’ve added a swap entry.
You learned how to create and enable Swap memory on an EC2 Linux instance in this tutorial.
How AI Is Revolutionizing ECommerce Email Marketing
In the digital age, eCommerce has become an integral part of our lives, and email marketing plays a pivotal role…