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

  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

How can I create a database from an sql backup file ?

First, create the database.. /path/to/bin/mysqladmin -u $mysqlusername -p$mysqlpassword create...

How can I see all running processes from my server?

Type the following command from shell prompt.It will display the currently running processes. ps...

Connecting to your Windows server

To connect to your Windows VPS or Dedicated server, you use Remote Desktop Connection. Go to:...

Connecting to your Linux server

To connect to your Linux VPS or Dedicated Server, you need a ssh client.  We recommend...

Memory usage seems too high inside a VPS

There are cases when you may notice that the memory usage is too high inside your VPS without a...