How to Create a Swap space on Ubuntu 16.x and Debian 8
Swap is space on a disk that is reserved to be used as virtual memory. A swap partition is not present on Cloud Servers by default, but swap can be added to a server by allocating a swap file.
We have discussed previously in 2 posts to create a SWAP space in Linux, this post describes create swap another method is,
Swap space method 1
Swap space method 2
You can add 1GB of swap to your server, fallocate command is really helpful.
$ sudo fallocate -l 1G /swapfile
If fallocate fails or is not installed this command, try swap space creation from the link,
Give read permission with below command,
$ sudo chmod 600 /swapfile
Format the file for swap.
$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=4d49c74c-4bfa-43ae-bff8-633f616e6ef0
Add the file to the system as a swap file.
$ sudo swapon /swapfile
Include the swapfile line to the end of /etc/fstab to make the change permanent.
$ sudo vim /etc/fstab
/swapfile none swap sw 0 0
Check that the swap file was created.
$ sudo swapon -s
Now, you can check the RAM space using free command,
$ free -m
total used free shared buffers cached
Mem: 3764 877 2887 1 160 204
-/+ buffers/cache: 512 3251
Swap: 1023 0 1023