Speaktech.in

fakeswap on VPS servers

[root@ip-184-168-90-206 ~]# swapon /home/swapfile
swapon: /home/swapfile: Operation not permitted

Solution

You you need to create a fakeswap on such VPS servers. Here is a script which I taken from http://linux-problem-solver.blogspot.in host.

a. Create a script file named “create_swap.sh”
b. Add this file content in it

#!/bin/bash
SWAP="${1:-512}"
NEW="$[SWAP*1024]"; TEMP="${NEW//?/ }"; OLD="${TEMP:1}0"
umount /proc/meminfo 2> /dev/null
sed "/^Swap\(Total\|Free\):/s,$OLD,$NEW," /proc/meminfo > /etc/fake_meminfo
mount --bind /etc/fake_meminfo /proc/meminfo
free -m

c. Apply the fake swap, if u want to increase the swap to 4GB, then apply the script as shown below,

Centos

[root@ip-18-16-90-06 installation]# sh create_swap.sh  4096

Ubuntu

[root@ip-18-16-90-06 installation]#bash create_swap.sh  4096

             total       used       free     shared    buffers     cached
Mem:          2048       1841        206          0          0          0
-/+ buffers/cache:       1841        206
Swap:         4096          0       4096
[root@ip-18-16-90-06 installation]#

Now you can see that SWAP value is added. Free command also will show the swap