Adding / Removing Swap on unix

To enable swap (Params: link)

sudo dd if=/dev/zero of=/mnt/1GB.swap bs=1024 count=1048576
chmod 0600 /mnt/1GB.swap
sudo mkswap /mnt/1GB.swap
sudo swapon /mnt/1GB.swap
free -m

To make it permenant so it will be reallocated upon restart add the following line to /etc/fstab

/mnt/1GB.swap               swap                    swap    defaults        0 0

To disable and remove swap

sudo swapoff /mnt/1GB.swap
rm /mnt/1GB.swap
free -m

Note:

This can be used to create a swap if dd doesnt work

sudo fallocate -l 1G /mnt/1GB.swap
Details
Updated: 5th December 2023

Play Blokr Now FREE!
blokr.io the web game where you can eat other blocks!