Last active
November 9, 2019 23:11
-
-
Save mhrubel/218bdace1671a6809b6c62b12678c4cc to your computer and use it in GitHub Desktop.
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
### Lets Check that swap file is already created or not | |
htop | |
## Use F10 Key from your keyboard to quit the htop screen! | |
## Lets create Swap file | |
## Use only one section from below 01 and 02 sections (1GB, 2GB) | |
## 01 Section - For 1GB Swap, use below commands (Section 01) | |
sudo fallocate -l 1G /swapfile | |
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576 | |
## 02 Section - For 2GB Swap, use below commands (Section 02) | |
sudo fallocate -l 2G /swapfile | |
sudo dd if=/dev/zero of=/swapfile bs=2048 count=1048576 | |
## For over 4GB or larger Physical RAM installed machine, I don't recommend using swap file, unless you do know what you are doing!! | |
sudo chmod 600 /swapfile | |
sudo mkswap /swapfile | |
sudo swapon /swapfile | |
### Lets edit FStab so it will be avaialiable after reboot | |
sudo nano /etc/fstab | |
### Just add below line end of this file | |
/swapfile swap swap defaults 0 0 | |
## Now save the file and exit | |
### Lets mount | |
sudo mount -a | |
## Now verfiy the swap file | |
htop | |
### Increase or Decrease the swap file later... | |
sudo swapoff -v /swapfile | |
## then follow the step from start! | |
## Completely remove the swap file | |
sudo swapoff -v /swapfile | |
sudo rm /swapfile | |
# Remove the fstab text that looks alike below text | |
/swapfile swap swap defaults 0 0 | |
# Now save the file and exit | |
sudo mount -a | |
# Now verfiy the swap file | |
htop | |
NOTE: This guide should work with almost all Ubuntu and Debian based OS versions... | |
This should works with all kind of VPS or Dedicated servers provider worlwide... | |
EX: Amazon Ec2, Amazon Lightsail, DigitalOcean, Vultr, Alibaba Cloud, Google Cloud etc... | |
DISCLAIMER: I'm not responsible if you brake anything from the server using this guide! Use this guide at YOUR OWN RISK... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment