How To Create Swap Partition in Linux

Swap memory in linux is used when the amount of  physical memory (RAM) is full. If the system needs more memory resources and RAM is full, then inactive pages in memory are moved to swap space. swap spaces are located on hard drives. It has slower access time than physical memory . It is very important to know how to create a swap partition . 
When we are using physical RAM up to 2GB , the size of the swap should be memory is 2 times. But If the size of the physical RAM is more than 2GB , the size of the swap memory should be 1 times.

Create a SWAP partition :-

Follow these steps to create a SWAP partition in Linux.

fdisk is a partition table manipulator in linux .  To create a swap partition in /dev/sda , run the command given below –

partprobe is use to inform operating system about changes occurs in partition table.

To setup swap partition , use command mkswap

To print block devices attributes ,simply run command blkid as given below

To enable it at boot time , edit /etc/fstab to include

To enable swap partition immediately, use command swapon as given below . -a flag is used to available all devices which is marked as swap in /etc/fstab

To display swap uses summary by device , use command swapon -s as given below

When the system boot next time , it enables new  swap partition . you can verify it by viewing the output of the command /proc/swaps or free

swap partition

So in this short article , i explained you about how to create a swap partition in linux .  Please subscribe to newsletter for updated articles. We will discuss about many other topics in next articles.