Skip to content

Instantly share code, notes, and snippets.

@bertrandom
Created March 20, 2012 04:56
Show Gist options
  • Save bertrandom/2131510 to your computer and use it in GitHub Desktop.
Save bertrandom/2131510 to your computer and use it in GitHub Desktop.
Creates a 4 gig swap file and mounts it as swap space, used for EC2 small instances for on-boot ephemeral swap space, put it somewhere in boot init
#!/bin/bash
if swapon -s | grep -q /mnt/swapfile
then
echo "Swapfile already mounted"
else
if [ -e /mnt/swapfile ]
then
echo "Mounting swapfile"
swapon /mnt/swapfile
else
echo "Creating swapfile"
dd if=/dev/zero of=/mnt/swapfile bs=1M count=4096
mkswap /mnt/swapfile
swapon /mnt/swapfile
fi
fi
@bertrandom
Copy link
Author

cd /usr/sbin
curl -O https://raw.github.com/gist/2131510/9df83283df1cdf876d8faa107c16721f6ea93a24/ephemswap
chmod +x ephemswap

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