Difference between revisions of "Swap FAKE"

From MS Computech
Jump to: navigation, search
(Created page with "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 b...")
(No difference)

Revision as of 11:31, 28 January 2017

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

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