Managing SWAP File
Create New SWAP
Step 1: Deactivate and Remove SWAP if there is one already
Step 2: Remove SWAP file
$ rm -r /swapfile
Step 3:
$ dd if=/dev/zero of=/swap bs=1024 count=1024k
$ mkswap /swap
$ chmod 600 /swap
$ chown root:root /swap
$ swapon /swap
$ echo "10" > /proc/sys/vm/swappiness
$ echo "vm.swappiness = 10" >> /etc/sysctl.conf
$ echo "/swap none swap sw 0 0 " >> /etc/fstab #Danger: check if the swap file is alread in fstab before doing this
Increase the SWAP file
Step 1: Deactivate SWAP
$ sudo swapoff -a
Step 2: Increase the size of the swap file, here for 16GB for example:
$ sudo dd if=/dev/zero of=/swapfile bs=1G count=16
Step 3: Make the SWAP file and turn on SWAP
$ sudo mkswap /swapfile
$ sudo swapon /swapfile
Step 4: To check the current SWAP size
$ grep SwapTotal /proc/meminfo
Removing SWAP file
Step 1: Deactivate SWAP
$ sudo swapoff -v /swapfile
or
$ sudo swapoff -a
Step 2: Remove swap file entry from /etc/fstab
/swapfile swap swap defaults 0 0
Step 3: Remove or Delete the actual swap file
$ sudo rm /swapfile