#
Setup Swapfile
Create a file with 1GB size for the swap
fallocate -l 1G /swapfile
Change the permissions to read and write of the swapfile
chmod 600 /swapfile
Create the Swaparea in the file
mkswap /swapfile
Add the Swapfile to the /etc/fstab
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
Import the Swapfile
mount -a
Check if the Swapfile is correctly imported
sudo swapon --show
Output
NAME TYPE SIZE USED PRIO
/swapfile file 1024M 100.7M -1