Last active
May 4, 2016 12:31
-
-
Save dhensby/4ddbbfdb7f7ff6850ec6961de88ac493 to your computer and use it in GitHub Desktop.
Enable a swap file for CentOS7 RHEL Fedora
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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