2 # This script adds a 1GB swapfile to the system
6 echo "Command failed with code $code: $BASH_COMMAND"
13 function set_swappiness
() {
14 if ! grep -q '^vm.swappiness' /etc
/sysctl.conf
; then
16 sysctl
-w vm.swappiness
=10
17 echo vm.swappiness
= 10 >> /etc
/sysctl.conf
21 function get_new_swapfile
() {
22 for i
in `seq 0 99`; do
23 if [ ! -e /swapfile.
$i ]; then
28 # Seriously? 100 swapfiles already exist?
29 echo "too many swapfiles"
33 [ `id -u` -eq 0 ] ||
{ echo "You must be root to run this script"; exit 1; }
35 # how big? default 1GB
38 [ $num_gb -lt 1 ] && { echo "Please specify an integer >= 1"; exit 1; }
39 echo "Creating a ${num_gb}GB swapfile..."
43 SWAPFILE
=$
(get_new_swapfile
)
46 dd if=/dev
/zero of
=$SWAPFILE bs
=1k count
=$
(($num_gb * 1024)) conv
=excl
49 echo "$SWAPFILE swap swap auto 0 0" >> /etc
/fstab
51 echo 1GiB swapfile successfully added