Last active
May 26, 2021 14:12
-
-
Save phlinhng/7e35f2e780cb10a6c0b4872b171c4f1e to your computer and use it in GitHub Desktop.
Create swap file for linux VPS
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
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