Skip to content

Instantly share code, notes, and snippets.

@kimlindholm
Created February 13, 2012 14:54
Show Gist options
  • Save kimlindholm/1817411 to your computer and use it in GitHub Desktop.
Save kimlindholm/1817411 to your computer and use it in GitHub Desktop.
Create swapfile if not already present
#!/bin/bash
# Create swapfile if not already present. Default size is 2 GB.
if [ ${SWAP_SIZE_MEGABYTES:=2048} -eq 0 ];then
echo No swap size given, skipping.
else
if [ -e /swapfile ];then
echo /swapfile already exists, skipping.
else
echo Creating /swapfile of $SWAP_SIZE_MEGABYTES MB
dd if=/dev/zero of=/swapfile bs=1024 count=$(($SWAP_SIZE_MEGABYTES*1024))
mkswap /swapfile
fi
swapon /swapfile
echo Swap Status:
swapon -s
fi
@kimlindholm
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment