Wednesday, December 17, 2014

what is swap space in linux ?

Swap Space?
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.
Swap space is located on hard drives, which have a slower access time than physical memory.
Linux has two forms of swap space: the swap partition and the swap file. The swap partition is an independent section of the hard disk used solely for swapping; no other files can reside there. The swap file is a special file in the filesystem that resides amongst your system and data files.

Recommended System Swap Space:
Amount Of RAM
Amount Of Swap Space (minimum)
4GB or Less
2GB
4GB-16GB
4GB
16GB-64GB
8GB
64GB-256GB
16GB
256GB-512GB
32GB

Create Swap Space:
   1.    Create A patition:
            #fdisk /dev/sda
            Press ‘n’     (for new partition)
            First cylinder: press ‘enter’
            Last cylinder: 2048M       (here i want to make swap of 2GB so, create a 2GB Partition)
            Press ‘t’       (for changing the type of parttion)
            Write ‘82’      (write lable No. 82 For swap)
            Press ‘w’       (for save and exit)

Execute the ‘partx’ command for updates new partition.
              #partx –a /dev/sda

   2.    Format the partition. (My partition name is /dev/sda4)
               #mkswap /dev/sda4

   3.    Create a directory for mount the partition. ( my directory name is ‘swap’ )
               #mkdir /swap

   4.    Now edit the ‘fstab’ file and write these entries and save it.
                #vim /etc/fstab
               /dev/sda4      swap        swap      defaults    0 0
   5.    Now update/activate your swap partition by this command:
                   #swapon –a

   6.    For checking your your swap partition:
                   #swapon –s
The output is coming as;
Filename      Type       Size         Used       Priority
/dev/sda4      partition   2048         0              -1


No comments:

Post a Comment