Hi friends , today we are going to share a another useful Linux article – “swap space in Linux”. This article covers the different method used for creating swap in Linux . It also covers the complete step by step guide of swap creation and deletion in Linux.
SWAP SPACE IN LINUX–>
Before learning swap let’s understand what is paging in Linux. The physical memory (RAM) in Linux is divided into chucks of memory. These chucks of memory are called pages. So a process in which a page of memory is copied to a preassigned space on the harddisk is called swapping and this preassigned space is called swap space in Linux.
Swapping comes in action when a system requires more amount of memory than the physically available memory.The required swap memory is assigned to a process that needs the memory immediately.
Swap memory is very slow compared to RAM. Swap memory is measured in miliseconds whereas the speed of main memory is in nanoseconds.
Read also:
|1|Complete tutorial on SSH server configuration in Rhel5/Rhel6.
|2|How to configure Postfix Server in Linux ?
|3|User and group management in Linux.
Commonly there are two type of swap space used in Linux==>
Swap partition
Swap file
So to understand Linux swapping procedure we have to understand Linux swap partition and Linux swap file.
SWAP PARTITION IN LINUX
In this section we will learn how to create and remove a swap partition in Linux. To make it easy i have divided the whole process into steps. Let’s get started.
HOW TO CREATE SWAP PARTITION IN LINUX???
Creation of swap partition in Linux is a normal & easy process . I have written a step by step process to explain swap file creation in Linux.
Step by step procedure of swap partition creation is as follows–>
STEP 1
First of all we have to create a partition and set it type to linux swap. If you don’t know how to create a paritition in Linux and how to change partiton type then first read this article – How to create partition in Linux?
STEP 2
Now we have to format the partition to use it as a swap partition.
#mkswap /dev/sda13
STEP 3
Now we have to turn on the swap and then after we check our swap creation as shown below.
#swapon /dev/sda13
#cat /proc/swaps
STEP 4–>
Now let’s do its entry in /etc/fstab file so that after reboot our swap partition will not automatically get removed.
So we have successfully created a swap partition in Linux.
HOW TO REMOVE SWAP PARTITION IN LINUX ???
After successfully creating swap partition in Linux now let’s learn how to remove swap partition in Linux. Let’s dive into step by step procedure.
STEP 1
In order to remove swap partition First of all we have to remove permanent mounting of swap partition.
simply type below command ==>
#vim /etc/fstab
press I to enter into the insert mode and simply remove the entry of swap partition and save it.
STEP 2
Now we have to turn off the swap by following command–>
#swapoff /dev/sda13
STEP 3
After turning off the swap we have to delete the swap partition in order to permanently remove it–>
So now the swap partition is completely removed from Linux.
SWAP CREATION BY ‘SWAP FILE’
As we discussed early that there are two types of swapping in Linux. We have already discussed the swap creation on partition .Now the second method of swapping is ‘swap file’ creation. In this process first we have to create a file and then after we have to manually create swap on it. To understand the process read this step by step guide –>
STEP 1
First of all create a directory named /raja .Enter into the directory and create a file of 100 mb.
#mkdir /raja (i have created this file on root so i use / sign)
#cd /raja
#dd if = /dev/zero of = sam bs =1M count = 100
STEP 2
Now format this file and turn on swap on it.
#mkswap sam
#swapon sam
STEP 3
Now check swap creation by following command
#cat /proc/swaps
STEP 4–>
Now do its entry in /etc/fstab.
So finally swap file is created.in Linux.
REMOVAL OF ‘SWAP FILE’
let’s learn how to remove swap file in Linux ==>
STEP 1–>
First of all remove entries from /etc/fstab file.
STEP 2
Now enter in /raja directory and turn off the swap on the file (sam) and delete the file.
#cd /raja
#swapoff sam ==> Turn off swap
#cat /proc/swaps ==> Check status
#rm -rf sam ==> delete file
#ls -l ==> check it
So it is the process of removal of swap file.
Conclusion
So we have learned about swap space in Linux and also the complete process of swap creation and deletion in Linux. Hope you like this article. Do follow us on twitter & share this article on Facebook & other social networking sites. Stay tuned ! more tutorials are coming soon !