Sunday, November 25, 2012

Swap Partition



Swap Partition
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space.
While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.
Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files.
The size of your swap should be equal to twice your computer's physical RAM for up to 2 GB of physical RAM. For physical RAM above 2 GB, the size of your swap should be equal

Some of useful commands in Swap creation
 mkswap:used to format the partition with swap file system
 swapon:to turnon the swap
swapoff:to turnoff the swap
Creation of swap partition
To accomplish this task you must be login form root account. So first login from root and verify your hard disk status with fdisk –l command ( This command will show that where your hard disk is mounted. You should use the mount point which show in the output of this command. For example if you see /dev/hda then you should use fdisk /dev/hda in next command. Or if you see /dev/sdb then you should use fdisk /dev/sdb in next command.

 [root@raju]#fdisk /dev/sda
command(mfor help):n
command(mfor help):e
First cylinder ("36495-38913", default 36495):
Using default value 36495
Last cylinder, +cylinders or +size{K,M,G} ("3649538913", default 38913): +500M
Command (m for help):t
 Command (m for help): 82        #file type of swap space is 82 so change file type to 82 of this newly created partition
 Command (m for help): w
[root@raju]#Partx -a  /dev/sda
[root@raju]#mkswap –f /dev/sda5
[root@raju]#swapon –a /dev/sda5
[root@raju]#swapon –s
Mounting swap partition
[root@raju~]#vi /etc/fstab
/dev/sda4   swap swap defaults 0 0
[root@raju~]#mount –a

To remove the swap partition
Turnoff swap
[root@raju~]#swapoff /dev/sda5
Remove the entry from rc.local
Remove the partition from /etc/fstab
Reboot the system

Stay Connected With Free Updates!

Subscribe via Email

Follow me!

Leave Your Comment Below If You Like This Post

0 comments: