make swap file linux - Image by Free-Photos from Pixabay

A swap is a kind of virtual memory storage where the rarely used pages of memory are stored. Swap storage becomes valuable if low memory or fast opcache PHP. Make swap file linux is required to faster your system.

Swap storage stored as a partition in a dedicated server but in virtual machines or some system, there is only one partition and no swap partition. Linux is making easy swap as a file. So, swap space can be both file or partition. If you have swap partition but require more swap space on a specific case, you can change your swap to file.

Make swap file linux

Firstly, please make sure you have swap exist or not

$ free -m
                   total        used        free      shared  buff/cache   available
Mem:            959         542          93          12         323         253
Swap:          2047           0        2047

If the swap is already exist, swap row will be show as above. If not, it will show as 0 in all ways.

If swap is exist, you can disable swap by 

$ swapoff -a

It will disable swap off

We will allocate swap file using a new empty file, 

$ fallocate -l 1G /swap

To protect access to root, we should change swap file permission

$ chomd 0600 /swap

We have to confirm that swap file will be used as swap

$ mkswap /swap

when mkswap is typed, swap file UUID will be generated, save it for future use.

Swap on the file using the following command

$ swapon /swap

You can confirm the swap file is working on by using the following command

free -m
                     total        used        free      shared  buff/cache   available
Mem:            959         542          93          12         323         253
Swap:          1024           0        1024

if your swap is permanent, configure the swap in /etc/fstab:

UUID=0fb38980-72bb-4a6b-bf90-afa91509b807 none  swap    sw      0   0


/swap  none   swap    sw    0  0

I hope this work with make swap file linux will help. 

By lwinmaungmaung on