From: Michael Brown Date: Tue, 22 Apr 2014 17:50:52 +0000 (-0400) Subject: mk_swapfile: add option to specify size in GB X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d6da9cd2f0e63c119879645b17610d480ab070da;p=discourse_docker.git mk_swapfile: add option to specify size in GB --- diff --git a/scripts/mk_swapfile b/scripts/mk_swapfile index 1bdaa91..0ccbd72 100755 --- a/scripts/mk_swapfile +++ b/scripts/mk_swapfile @@ -31,12 +31,19 @@ function get_new_swapfile() { } [ `id -u` -eq 0 ] || { echo "You must be root to run this script"; exit 1; } + +# how big? default 1GB +declare -i num_gb +num_gb="${1-1}" +[ $num_gb -lt 1 ] && { echo "Please specify an integer >= 1"; exit 1; } +echo "Creating a ${num_gb}GB swapfile..." + set_swappiness SWAPFILE=$(get_new_swapfile) umask 077 -dd if=/dev/zero of=$SWAPFILE bs=1k count=1024k conv=excl +dd if=/dev/zero of=$SWAPFILE bs=1k count=$(($num_gb * 1024)) conv=excl mkswap $SWAPFILE swapon $SWAPFILE echo "$SWAPFILE swap swap auto 0 0" >> /etc/fstab