How to create a swap memory on linux?

Run folloing command on CLI to create new swap file size: 1024M, you should change this size by your seft.

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024

/sbin/mkswap /var/swap.1

/sbin/swapon /var/swap.1

Resize swap:

/sbin/swapoff /var/swap.1

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=4096

/sbin/mkswap /var/swap.1

/sbin/swapon /var/swap.1

To start swap at boot

sudo cp /etc/fstab /etc/fstab.bak

echo '/var/swap.1 none swap sw 0 0' | sudo tee -a /etc/fstab

Above example to create swap.1 file and this file located at /etc/, futhermore swap file such as swap.2, swap.3, swap.4,…you could do the same way just need to change this swap file name.