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.
Commonly there are two type of swap space used in Linux==>
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–>
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?
Now we have to format the partition to use it as a swap partition.
Now we have to turn on the swap and then after we check our swap creation as shown below.
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.
In order to remove swap partition First of all we have to remove permanent mounting of swap partition.
simply type below command ==>
press I to enter into the insert mode and simply remove the entry of swap partition and save it.
Now we have to turn off the swap by following command–>
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 –>
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)
#dd if = /dev/zero of = sam bs =1M count = 100
Now format this file and turn on swap on it.
Now check swap creation by following command
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 ==>
First of all remove entries from /etc/fstab file.
Now enter in /raja directory and turn off the swap on the file (sam) and delete the file.
#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.
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 !