AWS : Adding swap to a running instance

This is nothing but a summary of the following guide on how to add a swap volume to a running instance on AWS :

By default instances started on AWS do not have allocated swap memory … but u should ALWAYS add a swap mem to your running instance to avoid lack of memory overhead!

  1. Check if you have any swap on your instance
    swapon -s
  2. If none, create a volume and attach it to the instance (you will have to assign it a letter in the format ‘sdf’, ‘sdg’, … etc. The added volume will be mounted on ‘/dev/xvdf’, ‘/dev/xvdg’, … etc. Here the example is run on ‘sdg’ mounted on ‘/dev/xvdg’.
  3. Execute
    lsblk

    to check your device (example ‘/dev/xvdg’)

  4. format the device for swap using
    sudo mkswap /dev/xvdg
  5. then execute

    sudo swapon /dev/xvdg
    
  6. Re-execute

    swapon -s

    to see your swap created!

  7. Modify your ‘/etc/fstab’ and add the following line

    /dev/xdvg       none    swap    sw      0       0
    

    to make the mount of the device persistent.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s