Skip to content

Instantly share code, notes, and snippets.

@rickyhewitt
Last active September 27, 2019 10:54
Show Gist options
  • Select an option

  • Save rickyhewitt/0e98bcad02fc44df17be to your computer and use it in GitHub Desktop.

Select an option

Save rickyhewitt/0e98bcad02fc44df17be to your computer and use it in GitHub Desktop.

Revisions

  1. rickyhewitt revised this gist Mar 24, 2019. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions createswap.sh
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,15 @@
    # 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
    echo "No swap size specified."
    exit 1; # fail
    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"
    @@ -19,5 +20,5 @@ mkswap /swap
    chmod 600 /swap
    swapon /swap
    sed -i -e '$a/swap none swap sw 0 0' /etc/fstab
    sysctl vm.swappiness=10
    sed -i -e '$avm.swappiness=10' /etc/sysctl.conf
    sysctl vm.swappiness=15
    sed -i -e '$avm.swappiness=15' /etc/sysctl.conf
  2. rickyhewitt revised this gist Sep 18, 2016. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions createswap.sh
    Original file line number Diff line number Diff line change
    @@ -5,15 +5,16 @@
    #
    # <[email protected]>

    SWAP_SIZE="512M"

    if [ $1 ]; then
    SWAP_SIZE=$1
    else
    echo "No swap size specified."
    exit 1; # fail
    fi

    echo "Creating swap file with size of $SWAP_SIZE"

    dd if=/dev/zero of=/swap bs=$SWAP_SIZE count=1
    fallocate -l $SWAP_SIZE /swap
    mkswap /swap
    chmod 600 /swap
    swapon /swap
  3. rickyhewitt created this gist Feb 18, 2016.
    22 changes: 22 additions & 0 deletions createswap.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/bin/sh
    # createswap.sh
    # creates swap file.
    # Optionally specify size (e.g. 1024M)
    #
    # <[email protected]>

    SWAP_SIZE="512M"

    if [ $1 ]; then
    SWAP_SIZE=$1
    fi

    echo "Creating swap file with size of $SWAP_SIZE"

    dd if=/dev/zero of=/swap bs=$SWAP_SIZE count=1
    mkswap /swap
    chmod 600 /swap
    swapon /swap
    sed -i -e '$a/swap none swap sw 0 0' /etc/fstab
    sysctl vm.swappiness=10
    sed -i -e '$avm.swappiness=10' /etc/sysctl.conf