Skip to content

Instantly share code, notes, and snippets.

@dhensby
Last active May 4, 2016 12:31
Show Gist options
  • Select an option

  • Save dhensby/4ddbbfdb7f7ff6850ec6961de88ac493 to your computer and use it in GitHub Desktop.

Select an option

Save dhensby/4ddbbfdb7f7ff6850ec6961de88ac493 to your computer and use it in GitHub Desktop.
Enable a swap file for CentOS7 RHEL Fedora
#!/usr/bin/env bash
SWAP_SIZE=1
if [[ $1 =~ ^-?[0-9]+$ ]]; then
SWAP_SIZE="$1"
fi
dd if=/dev/zero of=/swapfile count="$((${SWAP_SIZE} * 1024))" bs=1MiB
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap sw 0 0" >> /etc/fstab
sysctl vm.swappiness=10
echo "vm.swappiness = 10" >> /etc/sysctl.conf
sysctl vm.vfs_cache_pressure=50
echo "vm.vfs_cache_pressure = 50" >> /etc/sysctl.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment