Creating swap on Linux
This should work in any Linux distro
Create a swapfile
To create the swapfile let's just use the /dev/zero and append on /swapfile we're using 16MB blocks and making 64 of those, in another words 1GB, you can make 0.5GB or 4GB doesn't really matters:
dd if=/dev/zero of=/swapfile bs=16M count=64 # 1GB
or:
dd if=/dev/zero of=/swapfile bs=16M count=128 # 2GB
or:
dd if=/dev/zero of=/swapfile bs=16M count=256 # 4GB
Select one and go for it.
Changing file privileges to 600
Nothing crazy:
chmod 600 /swapfile
Formating this file as a swapfile
Just using mkswap and making /swapfile in fact a swapfile:
mkswap /swapfile
Activating swap on this file
To activate the swap now on this file you can just use swapon (swap on) and pass the file as a parameter:
swapon /swapfile
Deactivating swap on this file
To deactivate the swap on this file just use the inverse swapoff (swap off) and pass the file as a parameter.:
swapoff /swapfile
Appending swap configuration to fstab
Simple as this:
echo "/swapfile none swap sw 0 0" >> /etc/fstab
Or if you want to open the /etc/fstab file and append the configurations you can append just this:
/swapfile none swap sw 0 0
Single line and all done
dd if=/dev/zero of=/swapfile bs=16M count=128 ; chmod 600 /swapfile ; mkswap /swapfile ; swapon /swapfile ; echo "/swapfile none swap sw 0 0" >> /etc/fstab #2GB