Step1:First check what is the swap space the system is having and utilization of swap size
#free -m
#swapon -s
-s for st
#cat /proc/swaps
this will give output of swap statistics in Megabytes(m), if we want the output in Kilobytes then free -k
Step2:Before starting the Swap management we have to take precautions such as switch off all the swap and no user should be logged in
#swapoff -a
Step3:Check in the system if there is any raw space in the system
#fdisk -l
Step4:If the system is having free space then create a partition which support swap(partition type 82) with required amount of free space
#fdisk /dev/hda
p #press p to print the partition table
n #press n for creating new partition
256M #specify the amount of swap required
t #press t to change the partition type to 82 (because partition type 82 is well supported for swap)
8 #enter the partition no on which u want to create swap(here i am creating on /dev/hda8 partition)
82 #specifying the partition type
p #press p to print the partition table and to just conform the /dev/hda8 partition type
w #press w for writing the changes to partition table (if suppose if u have any problem or trouble just press q to quit from fdisk utility without any problem)
:wq
#mkswap /dev/hda8
Step5:update the partition table changes to kernel so that there is no need to restart the system/server
#partprob
Step6:Permanently mounting the partition details,in order to do this one we have to update the /etc/fstab file
#vi /etc/fstab
/dev/hda8 swap swap defaults 0 0
enter the above entires in to fstab file,save it and exit from editing /etc/fstab file
:wq
Step7:formatting/creating swap signature on the newly created partition
#mkswap /dev/hda8
Note:stpe6 and step7 are interchangeable.
Step8:update the mount table to kernel
#mount -a
Step9:now on the swap so that it can be available for use.
#swapon -a
Step10:check weather the swap is updated or not
#free -m
#swapon -s
#cat /proc/swaps
Removing swap:
Step1:Before doing any thing with swap first we have to switch of the swap
#swapoff -a
Step2:Remove/comment the entry of swap from /etc/fstab file
#vi /etc/fstab
then save and exit
Step3:update the kernel about mount table changes
#mount -a
Step4:Remove the partition used by swap
#fdisk /dev/hda8
d #press d to delete the partition
8 #specify the partition no to be deleted
w #press w to write the changes to partition table and quit the fdisk utility
Step5:update the partition table changes to kernel with out rebooting the system/server
#partprobe
Step6:now on the swap
#swapon -a
Step7:now check weather swap is updated properly or not
#free -m
#swapon -s
#cat /proc/swaps
Actually its advantageous if we create swap partition separately if the server is not having any raw space left what we can do ? At any cost we have to increase the swap to improve the system productivity
To come out of this situation there is one solution provided by Linux e.i we can create a swap file with in all ready existing and using partition if that partition is having sufficient free space
Step1:Switch off all the swap before any swap management
#swapoff -a
Step2:Determine what is the swap size we required(here i am taking 128MB) and execut the following command with count equal to 131072 (because 131072 is equal to 128M)
#dd if=/dev/zero of=/swapfile bs=1024 count=131072
Step3:Now set this swap file in order to use this file as swap
#mkswap /swapfile
Step4:Edit the /etc/fstab file to specify the swap file for perminient swap space
#vi /etc/fstab
/swapfile swap defaults 0 0
:wq
Step5:Update the kernel about the mount table changes
#mount -a
Step6:After managing the swap on the swap
#swapon -a
Step6:Check weather the swap space is updated or not by using following commands
#free -m
#swapon -s
#cat /proc/swaps
Removing swap:
Step1:Before doing any thing with swap first we have to switch of the swap
#swapoff -v /swapfile
Step2:Remove/comment the entry of swap from /etc/fstab file
#vi /etc/fstab
then save and exit
Step3:update the kernel about mount table changes
#mount -a
Step4:Remove the swapfile permanently
#rm /swapfile