How to enable swap inside your VPS?

A lot of people are asking about swap in an OpenVZ VPS.

Usually swap is not good but in some cases there are applications that need swap, or need at least to see swap available in order to  run correctly.

In order to make your VPS believe it has a swap partition you can use the script below. We also recommend you to run the script at system startup also.

You need to remember that this will not actually be a real swap partition and should read the article, following the link at the bottom.

 

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

The script was taken from: http://forum.openvz.org/index.php?t=msg&goto=27275&

Thanks to Thomas Sattler

  • 38 Users Found This Useful
Was this answer helpful?

Related Articles

Protecting SSH with Fail2Ban

About fail2ban If a server is exposed to the Internet, attackers will scan that server for as...

How to enable PPP (PPPD) on a OpenVZ VPS

In order to activate PPP (PPPD) on your OpenVZ VPS log into Hypanel, go to Machine...

How to install and configure OpenVPN

This howto will show you how to install OpenVPN inside an OpenVZ VPS on Ubuntu.OpenVZ supports...

The first Step to install Windows KVM Server

Windows KVM Server - Fast Setup include RDP https://www.youtube.com/watch?v=m2VTrWqB3EI

How to change my ssh port

IMPORTANT: Beofre changing your port, make sure the new port is whitelisted in your firewall, if...