Add more Swap on linux Vm

How to add more swap on a linux Vm.
It can be used on a physical machine too but remember that swap is store on a file and not in a dedicate partition.

#########################sWap File
#Create Local Folder
mkdir -p /usr/local/swap/

#Create a 2Gb Local File to store swap
dd if=/dev/zero of=/usr/local/swap/swapfile1 bs=1024 count=2097152 #2gb 4194304
mkswap /usr/local/swap/swapfile1

#set Grant On File
cd /usr/local/swap/
chown root:root swapfile1
chmod 0600 swapfile1

#Enable Swap
swapon swapfile1

Add this line in /ect/fstab to load swap on system startup:


/usr/local/swap/swapfile1 swap swap defaults 0 0