Skip to content

Instantly share code, notes, and snippets.

@bbl
Last active November 14, 2017 15:16
Show Gist options
  • Save bbl/4894319e123cbe2c9067d65f588633fc to your computer and use it in GitHub Desktop.
Save bbl/4894319e123cbe2c9067d65f588633fc to your computer and use it in GitHub Desktop.
Create and use swap on aws instance (or any other ubuntu machine)

Platform: Ubuntu 16.04

  1. It is common practice to create swap that equals to your RAM. So firstly, you should find out your RAM:
free -m

Which outputs like:

              total        used        free      shared  buff/cache   available
Mem:          32046       18549        4831        1273        8665       11644

In my case RAM = 32046 (mb). So the amount of swap should be around that value. The command to determine RAM automatically:

free -m |sed -n 2p| awk '{print $2}'
  1. After you've found your $SWAP_SIZE you can add swap:
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=${SWAP_SIZE}
sudo /sbin/mkswap /var/swap.1
sudo chmod 600 /var/swap.1
sudo /sbin/swapon /var/swap.1
sudo bash -c "echo '/var/swap.1 swap swap defaults 0 0' >> /etc/fstab"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment