Swap FAKE

From MS Computech
Revision as of 11:46, 28 January 2017 by Snifer (talk | contribs)
Jump to: navigation, search

Create Fake Swap in OpenVZ VPS if you get swapon failed: Operation not permitted Error

if you get swapon failed: Operation not permitted Error even if you run as root it is because in your VPS swap creation is not allowed follow below steps to Create Fake Swap in OpenVZ VPS

#!/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

[root@node1 appp]# ./swapfake.sh

             total        used        free      shared  buff/cache   available

Mem: 2048 343 930 133 774 1469 Swap: 512 0 512

[root@node1 appp]# ./swapfake.sh 2048

             total        used        free      shared  buff/cache   available

Mem: 2048 337 935 133 774 1474 Swap: 2048 0 2048

Sort Memory Usage

 ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r | less

@ Test work on OpenVZ Centos 7 Snifer (talk) 04:31, 28 January 2017 (UTC)