# 1. Allocate space for a 16GB swap file
sudo fallocate -l 16G /swapfile
 
# 2. Set secure permissions (only root can read/write)
sudo chmod 600 /swapfile
 
# 3. Set up the file as a Linux swap area
sudo mkswap /swapfile
 
# 4. Enable the swap file immediately
sudo swapon /swapfile
 
# 5. Make the change permanent across reboots
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab