Last active
September 27, 2019 10:54
-
-
Save rickyhewitt/0e98bcad02fc44df17be to your computer and use it in GitHub Desktop.
Quick and easy script to setup swap
This file contains 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
#!/bin/sh | |
# createswap.sh | |
# creates swap file. | |
# Optionally specify size (e.g. 1024M) | |
# If no size is specified, default to physical memory / 4 | |
# | |
# <[email protected]> | |
if [ $1 ]; then | |
SWAP_SIZE=$1 | |
else | |
PHYSICAL_MEM=$(head /proc/meminfo | awk 'BEGIN {OFS = FS} NR==1{print $2}') | |
SWAP_SIZE=$(($PHYSICAL_MEM/4)) | |
fi | |
echo "Creating swap file with size of $SWAP_SIZE" | |
fallocate -l $SWAP_SIZE /swap | |
mkswap /swap | |
chmod 600 /swap | |
swapon /swap | |
sed -i -e '$a/swap none swap sw 0 0' /etc/fstab | |
sysctl vm.swappiness=15 | |
sed -i -e '$avm.swappiness=15' /etc/sysctl.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment