Swap file creation Guide 6 on CentOS

In the previous post I wrote detailed instructions how to create a swap file on Ubuntu, on CentOS, the operation is similar to that.

Check the swap file

Before proceeding to create swap file needs to check that the current system has created this file by running:


If no, what information demonstrate the server returns no swap files and you can create.

Check free space

Use the command df to check free space

Filesystem 1 k-blocks Used Available Use% Mounted on
/dev/hda 20642428 1347968 18245884 7%/

Create a swap file

Run the command dd. here I create 1 GB swap (count = 1024k) for VPS 512RAM

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

Create a swap partition

sudo mkswap/swapfile


Setting up swapspace version 1, size = 536866 kB

Activate swap

sudo/swapfile swapon

Information swap file

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

Set the swap is automatically used each time reboot the server

echo/swapfile none swap defaults 0 0 > >/etc/fstab
echo swappiness = 0 vm. > > sysctl-p & &/etc/sysctl.conf

Swap file security by chmod

sudo chown root: root/swapfile
sudo chmod 0600/swapfile

Install the swap file

You can check out the swap file usage of the system by running the following command line



Swappiness parameter can range from 0 to 100. 100 is the regular use of swap and at this time you should upgrade the RAM for the server, 0 is rarely used.

You can adjust the parameters by using the sysctl command swappiness

sysctl vm. swappiness = 10

vm. swappiness = 10

Check back



To make sure keep this parameter each time to restart VPS you should add the following line to the file/etc/sysctl.conf

sudo nano/etc/sysctl.conf

# Search for the vm. swappiness setting. Uncomment and change it as necessary.
vm. swappiness = 10

Leave a Reply

Your email address will not be published.