Home Knowledge Base Fantacy Script & Apps How to create and enable the swap file?

How to create and enable the swap file?

To create the swap file using the dd command :

sudo dd if=/dev/zero of=/swapfile bs=1024 count=256k

“of=/swapfile” designates the file’s name. In this case the name is swapfile.

Subsequently we are going to code the swap file by creating a linux swap area:

sudo mkswap /swapfile

The result shown as below:

Setting up swapspace version 1, size = 262140 KiB
no label, UUID=103c4545-5fc5-47f3-a8b3-dfbdb64fd7eb

Finish it by activating the swap file:

sudo swapon /swapfile

After that You will be able to view the new swap file. when you view the swap summary.

swapon -s
Filename                Type        Size    Used    Priority
/swapfile                               file        262140    0    -1

This file will last in the virtual private server until the machine reboots. You can ensure that the swap is permanent by adding it to the fstab file.

Open up the file:

sudo nano /etc/fstab

Paste as below:

/swapfile       none    swap    sw      0       0