Skip to content

Instantly share code, notes, and snippets.

@oparrish2
Created November 11, 2011 18:08
Show Gist options
  • Save oparrish2/1358720 to your computer and use it in GitHub Desktop.
Save oparrish2/1358720 to your computer and use it in GitHub Desktop.
Script for creating a filesystem swap file on Linux
#!/bin/bash
SWAP_SIZE_MEGABYTES=$1
if [ $SWAP_SIZE_MEGABYTES -eq 0 ];then
echo No swap size given, skipping.
else
if [ -e /swapfile ];then
echo /swapfile already exists, skiping.
else
echo Creating /swapfile of $SWAP_SIZE_MEGABYTES Megabytes
dd if=/dev/zero of=/swapfile bs=1024 count=$(($SWAP_SIZE_MEGABYTES*1024))
mkswap /swapfile
swapon /swapfile
echo Swap Status:
swapon -s
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment