Creating a swap file on vps

Even if you have sufficient memory in your server, it’s still a good idea to have a swap file.  In order to reduce disk IO.

Step #1: Login as the Root User

Firstly use the following command to check if you have any swap space already

free -m

The following output shows zero swap space

     total  used        free      shared  buff/cache   available
Mem: 7822   1390         506         492        5924        5569
Swap: 0      0          0

Now we need to create the swap file .Use below command to create 4 GB swap file ,adjust the value according to your need

Step #2: Create Swap File

sudo dd if=/dev/zero of=/swap count=4096 bs=1MiB

Step #3: Secure swap file by setting permission

sudo chmod 600 /swap

Step #4: Set up a Linux swap area by formating the swap file:

sudo mkswap /swap

Step #5: Enabling the swap file

sudo swapon /swap

Step #6: Update /etc/fstab file

To make the swap be automatically mounted after reboot, the following command will add it to your fstab

sudo echo "/swap swap swap sw 0 0" >> /etc/fstab

To verify swap is activated or not

Simply use the free command:

free -m
give following output
      total   used     free      shared  buff/cache   available
Mem: 7822     1390     506         492        5924        5569
Swap:4095     0        4095

Now you are all set.

Was this article helpful?
YesNo

Comments

  1. Aliana

    I have been browsing online more than 2 hours today, yet I never found any interesting
    article like yours. It’s pretty worth enough for me.

    In my opinion, if all webmasters and bloggers made
    good content as you did, the web will be much more useful than ever before.

  2. generic viagra walmart

    Thanks for any other wonderful article. The place else may just anyone get that
    type of info in such a perfect means of writing? I’ve a presentation subsequent week, and I am at the search for such info.

  3. Krystal

    Hi there i am kavin, its my first time to commenting anyplace, when i
    read this article i thought i could also create comment due to this good paragraph.

  4. Jacob

    Thank you, I’ve recently been searching for information about this subject
    for ages and yours is the greatest I’ve came upon till now.
    But, what concerning the bottom line? Are you certain concerning
    the supply?

  5. Braylee

    I do not know whether it’s just me or if everyone else
    encountering problems with your website. It seems like some
    of the written text on your posts are running off the screen. Can somebody else please comment and let me know if this is happening to them too?
    This might be a issue with my internet browser because I’ve had this happen previously.

    Thank you

  6. Skincell Pro Mole Remover Reviews

    Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something.
    I think that you could do with some pics to drive the message home a bit, but instead of that, this is
    fantastic blog. A fantastic read. I will certainly be back.

Leave a Reply

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