Firstly, we have to understand what is swap in linux???
Swap is one of the file system, which is used as a virtual RAM for the system, it provide the extra memory resource to the system when it is required. We can extend RAM space through this partition.
Now, we can see how we extend swap partition:
- First, we check the available RAM space of our system.
|[root@localhost ~]#Â freeÂ -m|
- Create a partition of swap type
|[root@localhost ~]#Â fdiskÂ Â /dev/sda|
When we type this command then some command option has been display then type â€˜mâ€™ show so many option like â€˜nâ€™ is used for to create partition, then asking partition type whether it is extended or primary we select one of them , then we change type of partition by Â â€˜tâ€™ .Here through â€˜lâ€™ we check hex code of swap then give it according to them then finally we save it from â€˜wâ€™ command.
- Tell the changes to kernel.
|[root@localhost ~]# partxÂ Â -aÂ Â /dev/sda|
- Â Â Â We can check our swap partition is made or not.
|[root@localhost ~]#Â fdiskÂ Â -l|
- Â Then we format our swap partition.
|[root@localhost ~]#Â mkswapÂ /dev/sdax|
Here x is partition number .When we run this command we get UUID no. also copy this no.
- Then we create swap partition entry in /etc/fstab file.
|[root@localhost ~]#Â vimÂ /etc/fstab|
When we open this file then paste the UUID number here(if we not get UUID no. then donâ€™t worry we do entry by using partition no directly).RememberÂ swap has no mount point so when we fill the entry of mount point of swap then we type â€˜swapâ€™ ,file system swap ,defaults 0 0(means it is not go from checking).
- Then finally we run the swapon command, which is used to enable the devices and file for paging and swapping.
|[root@localhost ~]#Â swaponÂ /dev/sdax|
- Â Then finally we verify whether our swap partition is extended or not.
|[root@localhost ~]# freeÂ -m|
Finally we have extended our swap partition.