Would you like to increase swap size in Linux. You may follow the below steps to do that.
Here I am increasing the swap size from 2GB to 4GB.
The free -m command shows that the swap memory is now 2GB,
root@server[~]# free -m total used free shared buffers cached Mem: 3954 3824 130 0 175 2091 -/+ buffers/cache: 1558 2396 Swap: 2047 0 2047
To create a swap file of 4GB you need to execute the following command.
root@server[~]#dd if=/dev/zero of=/path/to/new/swap bs=1M count=4096
This will create a new partition with 4GB space. To make it a swap partition you need to execute the following command.
root@server[~]# mkswap /path/to/new/swap
Now the swap file is created.
Next you need to properly edit fstab entry to replace the previous swap line. Previously it would be something like below entry.
LABEL=SWAP-sda6 swap swap pri=0,defaults 0 0
You need to change it to the following
/path/to/new/swap swap swap pri=0,defaults 0 0
and now save the fstab file and exit.
now turn the swap to off and then on it using the below command.
root@server[~]# swapoff root@server[~]# swapon
This will mount the new swap file. So you will the output as below.
root@server[~]# free -m total used free shared buffers cached Mem: 3954 3773 181 0 111 2048 -/+ buffers/cache: 1613 2341 Swap: 4096 0 4096
Please reboot the server if you need to check if the changes in fstab is working onboot.
Thank you for viewing helpinlinux.com