How to increase swap space in a Linux server?

It has been a common issue that in most of the cases the RAM gets upgraded after the server is live. For maximum utilization of the resources, it is recommended to create swap space of twice the amount of RAM. Hence if a RAM of 1GB is present in the server 2GB of swap space should be present. In order to create a swap space of 1GB.

dd if=/dev/zero of=/swapfile1 bs=1024 count=1048576
/sbin/mkswap -c -v1 /swapfile1
/sbin/swapon /swapfile1

Add the entry to /etc/fstab to automate it after a Reboot. Edit /etc/fstab and add the entry below.

/swapfile1 swap swap defaults 0 0

A new swap file can be created with new name replace the filename “swapfile1″ with a new one and follow the same procedure. The above commands are used to create 1GB swap. If the amount of RAM in the server is 2GB, then a swap file of 4GB is required.
The easiest way to create this swap file is to created four swap files of 1GB each.

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.