How to create swap space

Swap space is the area on a hard disk which is part of the Virtual Memory of your machine, which is a combination of accessible physical memory (RAM) and the swap space. Swap space is used when your system decides that it needs physical memory for active processes and there is insufficient unused physical memory available.

 
Linux has two forms of swap space: Swap partition and swap file.
 
1-  Swap partition :-   The swap partition is an independent section of the hard disk used solely for swapping; no other files can reside there.
2-  Swap file :-   The swap file is a special file in the filesystem that resides amongst your system and data files.
 
How to create swap file
 
Step-1 First of all create a swap file, use the dd command to create an empty file of 1GB file.
 
[ root @ leolinux ~ ]#   dd   if=/dev/zero   of=/var/swapfile   bs=1K   count=1048576

 

Step-2   Now use mkswap command to make file as swap file.

[ root @ leolinux ~ ]#  mkfswap   -c   -v1    /var/swapfile

 

Step-3  To make it useable in running system, run swapon command.

[ root @ leolinux ~ ]#   swapon   /var/swapfile

 

Step-4  to make it useable accross the reboot, write an entry in /etc/fstab file.

[ root @ leolinux ~ ]#   vim   /etc/fstab

 

/var/swapfile    swap    swap    defaults     0   0

ESC

:wq!

 

Step-5  To see the list of activated swap partition or file.

[ root @ leolinux ~ ]#   swapon   -s

                                             OR

[ root @ leolinux ~ ]#   cat     /proc/swaps

 

How to create swap partition

Step-1 First of all create empty partition of 1GB with 82 ID, using fdisk or graphical tool. Here I am using  /dev/hda5 as empty partition.

Step-2   Now use mkswap command to create swap partition
.

[ root @ leolinux ~ ]#  mkswap    /dev/hda5

 

Step-3  To make it useable in running system, run swapon command.

[ root @ leolinux ~ ]#   swapon   /dev/hda5

 

Step-4  to make it useable accross the reboot, write an entry in /etc/fstab file.

[ root @ leolinux ~ ]#   vim   /etc/fstab

 

/dev/hda5    swap    swap    defaults     0   0

ESC

:wq!

 

Step-5 To see the list of activated swap partition or file.

[ root @ leolinux ~ ]#   swapon   -s

                                             OR

[ root @ leolinux ~ ]#   cat     /proc/swaps

 

 

Yours suggestions and comments are always welcomed 

Cheer !!