X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Fsystem%2Fadd_swap_mount.sh;h=5ba4274efc8519daa526cf6f5d019e2c382580a0;hb=d77ff3fcce289ed850f42e1d54df7d5d149cc8de;hp=200cb365095decb42ec8f4b4ed4ff1b4e3966954;hpb=c8527998bb0cfdbb0244bd919b017fd8772155b2;p=feisty_meow.git diff --git a/scripts/system/add_swap_mount.sh b/scripts/system/add_swap_mount.sh index 200cb365..5ba4274e 100644 --- a/scripts/system/add_swap_mount.sh +++ b/scripts/system/add_swap_mount.sh @@ -1,22 +1,53 @@ #!/bin/bash -source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh" - -#hmmm: should be able to add a new swap drive if desired. - -#hmmm: why all the hard-coded paths below? - -/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 -check_result "creating swap file" - -/bin/chmod 600 /var/swap.1 -check_result "setting swap file permissions" - -/sbin/mkswap /var/swap.1 -check_result "formatting swap file as swap partition" - -/sbin/swapon /var/swap.1 -check_result "enabling new swap partition" +# auto-find the scripts, since we might want to run this as sudo. +export WORKDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" +source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" + +if [[ $EUID != 0 ]]; then + echo "This script must be run as root or sudo." + exit 1 +fi + +# optional parameters: the instance number of the swap file (best as a number), +# and the size of the swap file to add. +SWAP_INSTANCE="$1"; shift +SWAP_SIZE="$1"; shift + +if [ "$SWAP_INSTANCE" == "--help" ]; then + echo "\ +This script will add a swap partition for Linux that uses hard drive space for +swap memory. This increases the amount of available memory on RAM constrained +systems. It accepts two parameters: (1) the instance of the swap file, which +should be a small number not already used for a swap partition, and (2) the +size of the swap file in megabytes." + exit 0 +fi + +# if the swap instance variable is already set, then we'll use it. +# this allows multiple different swap partitions to be added. +if [ -z "$SWAP_INSTANCE" ]; then + SWAP_INSTANCE=1 +fi + +# allow the amount of swap space to be determined from outside the script. +# this is measured in megabytes. +if [ -z "$SWAP_SIZE" ]; then + SWAP_SIZE=2048 +fi + +/bin/dd if=/dev/zero of=/var/swap.${SWAP_INSTANCE} bs=1M count=${SWAP_SIZE} +test_or_die "creating swap file" + +/bin/chmod 600 /var/swap.${SWAP_INSTANCE} +test_or_die "setting swap file permissions" + +/sbin/mkswap /var/swap.${SWAP_INSTANCE} +test_or_die "formatting swap file as swap partition" + +/sbin/swapon /var/swap.${SWAP_INSTANCE} +test_or_die "enabling new swap partition" free