Adding SWAP space to AWS c3.medium instance

To add swap space use the following steps:

sudo to root

[ec2-user@ip-10-167-158-108 ~]$ sudo -s
[root@ip-10-167-158-108 ec2-user]#

Check the swap space

#CHECK SWAP space...
[ec2-user@ip-10-167-158-108 ~]$ grep SwapTotal /proc/meminfo
SwapTotal: 0 kB
[ec2-user@ip-10-167-158-108 ~]$

Add swap space

Type the following command to create 512MB swap file (1024 * 512MB = 524288 block size):

[root@ip-10-167-158-108 ec2-user]# dd if=/dev/zero of=/swapfile1 bs=4096 count=524288
524288+0 records in
524288+0 records out
2147483648 bytes (2.1 GB) copied, 35.4742 s, 60.5 MB/s
[root@ip-10-167-158-108 ec2-user]#

Secure the swap file

Setup correct file permission for security reasons, enter:

[root@ip-10-167-158-108 ec2-user]# chown root:root /swapfile1
[root@ip-10-167-158-108 ec2-user]# chmod 0600 /swapfile1
[root@ip-10-167-158-108 ec2-user]#

Setup swap file

[root@ip-10-167-158-108 ec2-user]# mkswap /swapfile1
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=ed80d452-3a9d-4b47-b5b9-9fb931b2ed13
[root@ip-10-167-158-108 ec2-user]#

Enable and Activate the swap file

[root@ip-10-167-158-108 ec2-user]# swapon /swapfile1
[root@ip-10-167-158-108 ec2-user]# sudo vi /etc/fstab

EDIT the fstable file...  ADD following lines...
/swapfile1 none swap sw 0 0

Save and close the file. Next time Linux comes up after reboot, it enables the new swap file for you automatically.

Rebooot and check the swap file usage

[root@ip-10-167-158-108 ec2-user]# sudo shutdown -r now
Connection to closed by remote host.
Connection to closed.
sudhakar@sudhakar-Latitude-E6420:~$ ssh -i Downloads/TSPORA.pem
Last login: Sun Nov 2 09:58:02 2014 from
[ec2-user@ip-10-167-158-108 ~]$ grep SwapTotal /proc/meminfo
SwapTotal: 2097148 kB
[ec2-user@ip-10-167-158-108 ~]$


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s