Codementor Events

Adding Swap Space

Published Feb 25, 2020

AWS offers t2 instances free with 1 GB or RAM and 30 GB of Harddisk.

I felt the 1 GB RAM is very less for running decent applications.

We can add swap space to the t2 instance and I was able to add 4GB of swapspace to the t2 instance with 1 GB of RAM.

sudo dd if=/dev/zero of=/swapfile bs=512M count=8
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s

Add this line in /etc/fstab
sudo vi /etc/fstab
/swapfile swap swap defaults 0 0

To Check if the swap addition is successful:
cat /proc/meminfo
free -h
swapon -s

Another important note:

As of this writing ( 18 Jan, 2020), the micro instances DO NOT come with ephemeral storage.

Its recommended to use ephemeral storage for swap space.
If there is NO ephemeral storage, its ok to use the EBS storage we allocated. This space will be taken out of the allocated storage ( which comes out of root file storage.).

Discover and read more posts from Rajaram K
get started
post commentsBe the first to share your opinion
Show more replies