How to add Linux Swap file if you don’t have Swap Partition

VIA

Assuming you want to put it in '/', create an empty 1024MB file:

dd if=/dev/zero of=/swap bs=2048k count=512

Format it as a swap file:

sudo mkswap /swap

Add it to your running Linux system:

swapon /swap

Add /swap to fstab for automatic swap activation:

echo "/swap none swap sw 0 0" >>/etc/fstab

Verify that you've added the newly created swap to your Linux based operating system:

free -m