Join our Discord Server
Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 570+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 8900+ members and discord server close to 2200+ members. You can follow him on Twitter(@ajeetsraina).

How to increae Swap space under Linux

56 sec read

“Can Linux be installed without swap space?”.

This question was asked to me on one of Linux System admin interview. It might confuse anyone who is still fresher and have no hands-on experience with swap terminology.But the reality is “Yes”. But if you did this, you should be ready to cope up with your Linux box next time you put extra load on your box.It will crash someday.Its always recommended to provide extra space for swap partition.Swap is only used when you have maximum load.

atemyram
This article discuss how to increase the swap space through adding swap file on Linux machine.

Lets proceed with the requisite steps to add swap file as shown below:

Lets use dd command to create swapfile. Then you need to use mkswap command to set up a Linux swap area on a device or in a file.

a) Log in as root user.

b) Run this command to create 512MB swap file (1024 * 512MB = 524288 block size):

  1. dd if=/dev/zero of=/swapf1 bs=1024 count=524288

c) Set up a Linux swap area:

  1. mkswap /swapf1

d) Activate /swapfile1 swap space immediately:

  1. swapon /swapf1

e) To activate /swapf1 after Linux system reboot, add entry to /etc/fstab file. Open this file using text editor such as vi:

  1. vi /etc/fstab

Then,append following line:

/swapf1 swap swap defaults 0 0

So next time Linux comes up after reboot, it enables the new swap file for you automatically.

Verifying if the swap is activated or not?

$ free -m

Hope the article proves useful for everyone who wants an extra swap space therein.

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 570+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 8900+ members and discord server close to 2200+ members. You can follow him on Twitter(@ajeetsraina).
Join our Discord Server