Physical memory full issue: Create Linux swap file after installing the linux operating system step by step guide
In this
article we learn how to create linux swap file after installing linux operating
system , how to activate swap file after installing the swap file and how to
remove swap file from linux operating system.
What is SWAP in linux
SWAP file
is a space on disk which is taking over the control that means all inactive
pages are moved from the physical memory of the system to the SWAP space when all physical memory is consumed or full.
How to create and activate SWAP file on disk of linux system
To create
SWAP file on disk of a linux system we need to execute the below command.
We want to
create SWAP file named (swapfile) with size 2GB on / partition.To do this we
execute the below command.
[root@techrideradmin
~]# dd if=/dev/zero of=/swapfile bs=1M count=2048
2048+0
records in
2048+0
records out
2147483648
bytes (2.1 GB) copied, 25.9823 s, 82.7 MB/s
Create Linux swap file after installing the linux operating system step by step guide
After creating this we
need to format it into SWAP. To do this we execute the below command.
[root@techrideradmin
~]# mkswap /swapfile
Setting
up swapspace version 1, size = 2097148 KiB
no
label, UUID=3653e4ed-30fb-4c7d-971f-4fd3bc22396e
Now we need to change
the permission of the SWAP file .Only root user can read and write the file. To
do this we need to execute the below command.
[root@techrideradmin
~]# chmod 600 /swapfile
To activate the SWAP
file and verify the SWAP file we need to
execute the below commands.
[root@techrideradmin
~]# swapon -a
[root@techrideradmin
~]# swapon -s
To make change
permanently we append the following line into the “/etc/fstab”.
/swapfile swap swap defaults 0 0
After doing all the
above steps we finally verify the SWAP file to execute the below command.
[root@techrideradmin
~]# free –g
How to remove SWAP file from the linux system.
To remove the SWAP
file from the linux system first we need to deactivate the SWAP file using the
below command.
[root@techrideradmin
~]# swapoff -a
After that we remove
the SWAP file entry from the “/etc/fstab”.
And finally we remove
the /swapfile using the below command.
[root@techrideradmin
~]# rm /swapfile
rm:
remove regular file `/swapfile'? y
0 comments:
Post a Comment