Skip to content

Instantly share code, notes, and snippets.

@goodfeel
Last active September 16, 2015 01:28
Show Gist options
  • Save goodfeel/906165ab23f522ba4341 to your computer and use it in GitHub Desktop.
Save goodfeel/906165ab23f522ba4341 to your computer and use it in GitHub Desktop.
Amazon AMI Swapfile Setup
sudo /bin/dd if=/dev/zero of=/var/swap1 bs=1G count=3 #(block size 1G for 3 which is 3GB in total)
# or sudo /bin/dd if=/dev/zero of=/var/swap1 bs=1M count=2048
sudo /sbin/mkswap /var/swap1
# Change permission so the swap file is secured.
sudo chmod 0600 /var/swap1
# Turn swap on
sudo /sbin/swapon /var/swap1
# Add auto (mount/)swapon when instance start
sudo vi /etc/fstab
# Add this to the file then save and exit
/var/swap1 swap swap defaults 0 0
# Then reboot to check the outcome
sudo reboot now
# Now you can use `top` and if you see something like this, you are good!
# Mem: 4050720k total, 768676k used, 3282044k free, 36148k buffers
# Swap: 2097148k total, 0k used, 2097148k free, 134536k cached
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment