Swap File
Resizing the file is the same process as making a swap file. So, you have three options:
- Add another swapfile. 2 files of 2GB is the same as one of 4GB (ie 4GB swap)
- Delete this file. and make a new one that is 4GB
- Reuse this file.
To make new or reuse your current file, you have to type:
sudo swapoff -a # turn off all swap
sudo rm /swapfile # this step is if you want to delete the current file
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096 #makes a 4GB file
sudo chmod 600 /swapfile #set permission to root only if you made a new file
sudo mkswap /swapfile #converts file to swap format
sudo swapon /swapfile #enable swap on the file.
寫到 fstab 開機自動掛載 swapfile 重開時會自動swap file
root@01:/# echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
=> /swapfile none swap sw 0 0