Creating a swap file on Ubuntu

This translation is made automatically from Russian

The paging file can be used by the server when there is a shortage of RAM. Of course, it is better to add new straps physically. But what to do if RAM needs to be increased urgently? The easiest way is to create a swap file using several commands.

Let’s switch to superuser mode:
 sudo su 

Create a 1024 megabyte file:
 dd if=/dev/zero of=/swap1 bs=1M count=1024 

Let’s convert this file to swap
 mkswap /swap1 

Change permissions
 chmod 600 /swap1 

And include the paging file:
 swapon /swap1 

To make the file available after reboot, you must add to /etc/fstab
 nano /etc/fstab 
this text:
 /swap1 swap swap def

You can disable an unnecessary paging file with the command
 swapoff /swap1 

By Oles Bykov

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.