2013-08-01

Swap space Partition in linux


Pranaam to all bhai ji _/\_
In this post we will discuss about swap space partition and its creation via command line .

swap space partition is that partition which is needed when we are running on low RAM in our system.
swap is used as RAM in system when we dont have enough space and we need to store data on RAM
requested by a process .
in short, swap is inactive RAM which role comes in play when our RAM is full :) . if we have enough RAM in our system , we dont require swap space.swap space memory size doesnt need to be set as DOUBLE OF SIZE OF RAM (as many people says).if we have enough RAM, we even dont need swap partiton.
so its depends on you, how much space you want to allocate as swap for your system.

alike storage partition, we dont mount swap partition but swap partition need to activate(on) so that system can use it :) .

ok lets starts, first of all we will learn , how to create swap space in linux environment(OS) .
There is little bit difference between creation normal partition type and swap partition. we just need to change partition type of new created partition via command line using fdisk utility(we have discussed about how to create partition using fdisk in post http://mannulinux.blogspot.com/2013/07/partition-or-file-system-creation-in.html )

so lets start
we need to enter into hard disk using fdisk command .to find out harddisk name run command  fdisk -l
and you will get output like this



my main hard disk name is  /dev/sda
command will be     fdisk  -c  /dev/sda
and i will be in hard disk with command line interface. now type n and press enter to enter into new partition creation mode.
select any partition type (either primary or logical as we will change it later so it doesnt matter).
i am selecting bydefault i.e primary partiton by typing p
select partition number or press enter for by default number(its 3 in my cse and new partition will be /dev/sda3  3 will be added with disk name /dev/sda+partition_number=/dev/sda3)
allocate the space , i am creating partition with 60 MB size by specifying +60M (you can specify total size of partition either by sector number, which is not comfortable or use  +sizeM/G M stands for MB and G stands for GB). have look on screenshot for batter understanding :) .


now we have to change partition into swap type .
type t in command line interface and press enter and prompt will ask for partition number whose type has to change. we have just created  partition 3 , type 3 and press enter. now screen will come up and will ask for  hex code of partition compatibility . for swap partition hex code is 82 and for other partition type hex code type l in command prompt and press enter .


here is the list of hex codes


ok , type 82 and press enter, we will get message that partition has changed into 82(linux swap)
it means , swap has been created.
to write changes on disk , type w and press enter to save changes to disk .
reboot system or run command partprobe to update partition table list in kernel


okkkkkk, we have updated kernel partition table too.
we need 2 more step to complete with swap.
now specify /dev/sda3 as swap by running this command " mkswap  partition_device_name "
example :-  mkswap  /dev/sda3


now run command to activate swap on system
command is :-  swapon partition_device_name
in my case partition_device_name is   /dev/sda3
so command is   swapon  /dev/sda3


hell yesh , we have done \m/
now run swapon -s command to check your activated swap partitions on you system with its available and used space :)
this was the procedure to create swap and activate it 
Thank you
Greetz to  :- Guru ji Zero and Whole Team IndiShell <3
Share this post

0 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

© 2009 Start With Linux | Mannu Linux
Designed by cyb3r.gladiat0r
Posts RSSComments RSS
Back to top