How To Add SWAP Space in Linux











CONFIGURATION STEPS ARE:





How to Add Swap Space on Linux

Swap is a space on a disk that is used when the amount
of physical RAM memory is full. When a Linux system runs out of RAM, inactive
pages are moved from the RAM to the swap space.
Swap space
can take the form of either a dedicated swap partition or a swap file. In most
cases when running Linux on a virtual machine a swap partition is not present
so our only option is to create a swap file.

1: create a swap file

Now we create
a swap file called "swapfile.img" on root (/) directory using the “fallocate”
command with the size of 1GB and you can adjust the size as per your needs
after create verify swap file.

# fallocate
-l 1G /swapfile.img

# ls -lh /swapfile.img

2: Enabling the Swap File

enable the
swap file and set the correct permissions on the file so that only the root
user can access to the file.

# chmod 600 / swapfile.img


3: Set up a Linux swap area.


Use the
mkswap utility to set up the file as Linux swap area and enable the swap file
to start utilizing it on the system.

# mkswap
/swapfile.img

# swapon
/swapfile.img

# swapon –show


4: Add swap file into fstab

To make the  change permanent open the /etc/fstab file and add this line:

# vim /etc/fstab

/swapfile.img     swap     swap     defaults     0     0



5: Verify that the swap space

# swapon –show

Or you can use

# free -h


Comments

Popular posts from this blog

How to install AnyDesk on Rhel 8 / Centos 8

Huawei OLT how to Add into U2000 NMS

How to install caching only dns server on Rhel 8 / Centos 8