Skip to content

Instantly share code, notes, and snippets.

@PauloBoaventura
Forked from clivewalkden/setup.sh
Created November 24, 2020 23:28
Show Gist options
  • Save PauloBoaventura/29b75bdcc2801ab84d44b54cfeaca095 to your computer and use it in GitHub Desktop.
Save PauloBoaventura/29b75bdcc2801ab84d44b54cfeaca095 to your computer and use it in GitHub Desktop.
How to add swap to CentOS 7
# Check if we already have swap
swapon -s
# Second Check
free -m
# Check available space
df -h
# Generate the file (4GB)
sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
# Set correct permissions
sudo chmod 600 /swapfile
# Make it swap
sudo mkswap /swapfile
# Turn it on
sudo swapon /swapfile
# Test
swapon -s
free -m
# To Make Permanent
sudo nano /etc/fstab
# Add the following
/swapfile swap swap sw 0 0
# Check Swappiness (default 30)
cat /proc/sys/vm/swappiness
# To change the level (60 on Mag2 Cluster)
sudo nano /etc/sysctl.conf
# Find the line
vm.swappiness = 60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment