How to Create a SWAP space in an AWS Micro Instance

aws-logoIf you are using a Micro Instance in AWS then you can find there is not swap space with it. But, it always requires a swap space if you are running applications that require a large amount of memory. The combined sizes of the physical memory and the swap space is the amount of virtual memory available. As per the old rule the swap partition should be twice the size of the physical memory. As per Red Hat Recommendation- “System with 4GB of ram or less require a minimum of 2GB of swap space”. In this article I will show you how to find out your swap space and how to create it.

First we will determine that how much swap space we have.

Here you can see that the swap space is 0.

Also you can verify the swap space using the below commands:

We can create swap space using two methods with dd, mkswap and swapon commands.

First Method:

Create a swap file

Make the file as a swap file

Enable the newly created swapfile

Second Method:

If you have additional free hard disk then you can use that as your swap partition. Assuming your free disk name as “/dev/sdf”

Enable the swap partition for usage:

To Make the swap space available after boot you have to edit the /etc/fstab file .

Now you can verify the swap space again using the earlier discussed commands.

The following two tabs change content below.

Tapas Mishra

Sr. Engineer (DevOps)
Loves to work on Opensource products. Having experience on Linux environment. Knowledge on Public cloud services like AWS, Rackspace, DigitalOcean, Linode. Please don't hesitate to give a comment on the posts. Your comments are my strength.

Leave a Reply