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

  • 41 Users Found This Useful
這篇文章有幫助嗎?

Related Articles

How to install and configure OpenVPN

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

How to change your VPS date/time?

Since we have a lot of people from all around the world almost anyone will need to have his VPS...

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 enable TUN/TAP on OpenVZ VPS?

In order to activate TUN/TAP on your OpenVZ VPS log into Hypanel, go...