Archive for the tag 'Swap Space'

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.

SBDavid

Adding Swap Space in LVM

To extend an LVM2 swap logical volume (assuming LogVol01 is the volume you want to extend):

1.Disable swapping for the associated logical volume:

# swapoff -v LogVol01

2.Resize the LVM2 logical volume by 500 MB:

# lvm lvresize LogVol01 -L +500M

3.Format the new swap space:

# mkswap LogVol01

4.Enable swap on the extended logical volume:

# swapon -va