Skip to content

Instantly share code, notes, and snippets.

@phlinhng
Last active May 26, 2021 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phlinhng/7e35f2e780cb10a6c0b4872b171c4f1e to your computer and use it in GitHub Desktop.
Save phlinhng/7e35f2e780cb10a6c0b4872b171c4f1e to your computer and use it in GitHub Desktop.
Create swap file for linux VPS
dd if=/dev/zero of=/swapfile bs=1024 count=1048576 # allocate space
chmod 600 /swapfile # set permission
mkswap /swapfile # make swap
swapon /swapfile # enable swap
echo "/swapfile swap swap defaults 0 0" | tee -a /etc/fstab # make swap permanent
sysctl -w "vm.swappiness=10" # set swap percentage
echo "vm.swappiness=10" | tee -a /etc/sysctl.conf # make systctl permanent
dd if=/dev/zero of=/swapfile bs=1024 count=524288 # allocate space
chmod 600 /swapfile # set permission
mkswap /swapfile # make swap
swapon /swapfile # enable swap
echo "/swapfile swap swap defaults 0 0" | tee -a /etc/fstab # make swap permanent
sysctl -w "vm.swappiness=10" # set swap percentage
echo "vm.swappiness=10" | tee -a /etc/sysctl.conf # make systctl permanent
swapoff /swapfile
nano /etc/fstab # edit /etc/fstab and remove the line "/swapfile swap swap defaults 0 0"
rm -rf /swapfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment