Linux Tips, Virtualization

How to increase Swap Size on Citrix VM or any Virtual Envirnoment

Swap Space is partition made on Linux systems which act as Virtual Memory. It uses the Hard disk space to enhance the memory management. There are many applications available in market which requires high swap space to work but due to physical hardware sometime its not possible but this is not the case with Virtualization. The biggest advantage of Virtualization is you can get on-demand resources. In this post I am going to explain how you can increase the SWAP Space size on Cirtix VM (Virtual Machine) or Virtualization platform (like vmware).

To add or increase the swap size first you have to add a new virtual disk to the VM. Please check “ADD ADDITIONAL DISK SPACE” section of Extend partition size in Linux LVM (Citrix Xen) without downtime. You should add the disk of exact Swap size you required, let say you need 5Gb of Swap and existing swap size is 2 GB so you need to add disk of 5GB instead of 3 GB.

Configuring Swap

1) Check your Current Swap Size: Use command free -m to see the Memory Utilization including Swap.

[root@centos ~]# free -m


2) Now execute “fdisk” command to check if the new disk detected by the VM or not

[root@centos ~]# fdisk -l


3) Now initialize the PhysicalVolume using command ā€œpvcreateā€

[root@centos ~]# pvcreate /dev/xvde
Physical volume “/dev/xvde” successfully created
[root@centos ~]#

4) Create a new Volume Group named “Swap” with “vgcreate

[root@centos ~]# vgcreate swap /dev/xvde
Volume group “swap” successfully created
[root@centos ~]#

5) Verify if the Volume Group has been created or not with command “vgscan“.

[root@centos ~]# vgscan
Reading all physical volumes. This may take a while…
Found volume group “swap” using metadata type lvm2
Found volume group “VolGroup00” using metadata type lvm2
[root@centos ~]#


6) Create new Logical Volume using “lvcreate” command.

[root@centos ~]# lvcreate swap -n lvol0 -L 5000M

Here, 5000M is the size of Logical Volume.

7) Format the swap Volume Group to used as a swap device.

Check Volume Path

[root@centos ~]# ls /dev/swap/lvol0
[root@centos ~]#

Format the Volume

[root@centos ~]# mkswap /dev/swap/lvol0
Setting up swapspace version 1, size = 5364510 kB
[root@centos ~]#


7) Switch Off the existing Swap Space using command “swapoff” and then verify it using “free -m

[root@centos ~]# swapoff -av
swapoff on /dev/mapper/VolGroup00-LogVol01
[root@centos ~]# free -m
total used free shared buffers cached
Mem: 1608 967 640 0 156 365
-/+ buffers/cache: 445 1162
Swap: 0 0 0
[root@centos ~]#


8) Now open “/etc/fstab” file and search for

/dev/VolGroup00/LogVol01 swap swap defaults 0 0

Change it to the Swap Volume we have created

/dev/swap/lvol0 swap swap defaults 0 0

9) Switch on the swap space by executing the command “swapon

[root@centos ~]# swapon -av
swapon on /dev/swap/lvol0

Now check the swap size

[root@centos ~]# free -m
total used free shared buffers cached
Mem: 1608 970 637 0 156 365
-/+ buffers/cache: 448 1159
Swap: 5115 0 5115
[root@centos ~]#


1 Comment

  1. Nice post. Fully informative thanks…

Leave a Reply