Skip to content

Instantly share code, notes, and snippets.

@mrl22
Forked from dgoguerra/create-swapfile.md
Created September 9, 2021 17:36
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 mrl22/08c0123511e09dd5c31bd2d615a6bf02 to your computer and use it in GitHub Desktop.
Save mrl22/08c0123511e09dd5c31bd2d615a6bf02 to your computer and use it in GitHub Desktop.
create swapfile in ubuntu

Taken from a DigitalOcean tutorial.

Create and enable swapfile:

# create a 2GB file only accessible by root
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile

# mark the file as a swap space
sudo mkswap /swapfile
# enable the swap file
sudo swapon /swapfile

Verify the swap is available:

sudo swapon --show
free -h

Make the swap permanent:

# backup fstab just in case
sudo cp /etc/fstab /etc/fstab.bak
# add the swapfile at the end of fstab
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment