3 # auto-find the scripts, since we might want to run this as sudo.
4 export THISDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )" # obtain the script's working directory.
5 export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )"
6 source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh"
8 if [[ $EUID != 0 ]]; then
9 echo "This script must be run as root or sudo."
13 # optional parameters: the instance number of the swap file (best as a number),
14 # and the size of the swap file to add.
15 SWAP_INSTANCE="$1"; shift
18 if [ "$SWAP_INSTANCE" == "--help" ]; then
21 This script will add a swap partition for Linux that uses hard drive space for
22 swap memory. This increases the amount of available memory on RAM constrained
23 systems. It accepts two parameters: (1) the instance of the swap file, which
24 should be a small number not already used for a swap partition, and (2) the
25 size of the swap file in megabytes."
29 # if the swap instance variable is already set, then we'll use it.
30 # this allows multiple different swap partitions to be added.
31 if [ -z "$SWAP_INSTANCE" ]; then
35 # allow the amount of swap space to be determined from outside the script.
36 # this is measured in megabytes.
37 if [ -z "$SWAP_SIZE" ]; then
41 /bin/dd if=/dev/zero of=/var/swap.${SWAP_INSTANCE} bs=1M count=${SWAP_SIZE}
42 exit_on_error "creating swap file"
44 /bin/chmod 600 /var/swap.${SWAP_INSTANCE}
45 exit_on_error "setting swap file permissions"
47 /sbin/mkswap /var/swap.${SWAP_INSTANCE}
48 exit_on_error "formatting swap file as swap partition"
50 /sbin/swapon /var/swap.${SWAP_INSTANCE}
51 exit_on_error "enabling new swap partition"