Skip to content

Instantly share code, notes, and snippets.

@rokumatsumoto
Last active May 5, 2019 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rokumatsumoto/936ed7aa777a01a1f03244d3e91593ff to your computer and use it in GitHub Desktop.
Save rokumatsumoto/936ed7aa777a01a1f03244d3e91593ff to your computer and use it in GitHub Desktop.
Create Swap Space on Ubuntu, Amazon Linux AMI

To check how much available RAM memory you have free:

free -m

To see if you have a swap files:

sudo swapon -s

No swap file shown? Check how much disk space you have:

df

To create a swap file:

Step 1: Allocate a file for swap

sudo fallocate -l 2048m /mnt/swap_file.swap

Step 2: Change permission

sudo chmod 600 /mnt/swap_file.swap

Step 3: Format the file for swapping device

sudo mkswap /mnt/swap_file.swap

Step 4: Enable the swap

sudo swapon /mnt/swap_file.swap

Step 5: Make sure the swap is mounted when you Reboot. First, open fstab

sudo vim /etc/fstab

Finally, add entry in fstab (only if it wasn't automatically added)

/etc/fstab

/mnt/swap_file.swap none swap sw 0 0

Save and exit. You're done adding swap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment