Created
January 6, 2020 06:15
-
-
Save roeniss/a7f4b166c3fa25f10468194af432d670 to your computer and use it in GitHub Desktop.
makeSwap.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# original article: [How To Add Swap Space on Ubuntu 16.04](https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04) | |
# Cautious! Upgrading RAM is safer than this job. | |
# 1. check status | |
sudo swapon --show # no output == no available swap space | |
free -h # another way to do right above line | |
df -h # check available disk | |
# 2. create/enable swap file | |
sudo fallocate -l 1G /swapfile # "'fallocate' creates a file of a preallocated size instantly." | |
sudo chmod 600 /swapfile # "This prevents normal users from being able to access the file, which would have significant security implications." | |
ls -lh /swapfile # verify if above jobs correctly done | |
sudo mkswap /swapfile # "mark the file as swap space by typing this" | |
sudo swapon /swapfile # "allowing our system to start utilizing it" | |
sudo swapon --show # check if the swap is available now | |
free -h # another way to do right above line | |
# 3. make the swap permanent | |
# ''' Our recent changes have enabled the swap file for the current session. However, if we reboot, the server will not retain the swap settings automatically. We can change this by adding the swap file to our /etc/fstab file. ''' | |
sudo cp /etc/fstab /etc/fstab.bak # "Back up the /etc/fstab file in case anything goes wrong" | |
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab # add line to /etc/fstab | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AWS introduced another command,
dd
: https://aws.amazon.com/ko/premiumsupport/knowledge-center/ec2-memory-swap-file/sudo dd if=/dev/zero of=/swapfile bs=128M count=32 sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo swapon -s sudo vi /etc/fstab # add: /swapfile swap swap defaults 0 0