- Determine the amount of existing swap space
This will list any swap partitions and swap files currently in use. Your swap space should be at least twice the amount of physical RAM installed for best results. For example, a system with 512MB of physical RAM should have at least 1GB of swap space.Code: Select all
more /proc/swaps
To configure 2GB of swap, we can make one 2GB swap file or two 1GB swap files. We'll do two 1GB swap files because one 2GB swap file might not work depending on Linux kernel support for large files (file over 2GB). - Make swap files named swapfile1 and swapfile2 in /var/tmp
This creates the files /var/tmp/swapfile1 and /var/tmp/swapfile2, each 1GB in size. Using the "dd" command ensures that the files have no holes.
Code: Select all
cd /var/tmp dd if=/dev/zero of=swapfile1 bs=1024 count=1048576 dd if=/dev/zero of=swapfile2 bs=1024 count=1048576
- Turn each swap file into a swap area
Code: Select all
/sbin/mkswap -c -v1 /var/tmp/swapfile1 /sbin/mkswap -c -v1 /var/tmp/swapfile2
- Turn on swap files
If you getting the error message, swapon: swapfile: Operation not permitted. then you must be in a VPS without rights to create swap files. Make sure you are logged in as root as well.
Code: Select all
# swapon /var/tmp/swapfile1 # swapon /var/tmp/swapfile2
- Verify that the system is using the swap file
You should see entries for /var/tmp/swapfile1 and swapfile2.
Code: Select all
more /proc/swaps
- Set up your system to load the swap space at startup
In /etc/rc.d/rc.sysinit, look for a line that contains:Append this command to enable your swap files at startup:Code: Select all
swapon -a
The line should now look something like this:Code: Select all
swapon /var/tmp/swapfile1 swapon /var/tmp/swapfile2
Code: Select all
action "Activating swap partitions" swapon -a swapon /var/tmp/swapfile1 swapon /var/tmp/swapfile2
How to create swap in linux
How to create swap in linux
These are the steps to add swap space to your Linux system through the use of swap files. Be sure to login as root user.