How to enable swap inside your VPS? Print

  • 40

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.


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:

Thanks to Thomas Sattler

Was this answer helpful?

« Back