Skip to content

Instantly share code, notes, and snippets.

@ooMia
Last active June 7, 2024 02:19
Show Gist options
  • Save ooMia/9a0cfd5f7f9a618baa62542633d457b8 to your computer and use it in GitHub Desktop.
Save ooMia/9a0cfd5f7f9a618baa62542633d457b8 to your computer and use it in GitHub Desktop.
AWS instance swap memory auto-configure shell script
#!/bin/bash
# running command
# wget https://gist.githubusercontent.com/ooMia/9a0cfd5f7f9a618baa62542633d457b8/raw/a36ca84d3e6a888a39bef61a9f4160b24c3472f9/swap-2G.sh -O swap.sh && sudo chmod +x swap.sh && ./swap.sh
# ref: https://repost.aws/knowledge-center/ec2-memory-swap-file
# 1. create a swap file on the root file system
sudo dd if=/dev/zero of=/swapfile bs=64M count=32
# 2. Update the read and write permissions for the swap file
sudo chmod 600 /swapfile
# 3. Set up a Linux swap area
sudo mkswap /swapfile
# 4. Make the swap file available for immediate use
sudo swapon /swapfile
# 5. Verify that the procedure was successful
sudo swapon -s
# 6. Start the swap file at boot time
echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment