How to add Swap file in Linux
2024-02-20- Create a file that will be used for swap
sudo fallocate -l 4G /swapfile
- Set the correct permissions for swap file
sudo chmod 600 /swapfile
- Use the mkswap utility to set up the file as Linux swap area
sudo mkswap /swapfile
- Enable the swap with the following command
sudo swapon /swapfile
- if Need to make the change permanent, then update the /etc/fstab file and append the following line
/swapfile swap swap defaults 0 0
- To verify that the swap is active
sudo swapon --show free -h