top of page
DBA Genesis Docs logo

Add Swap Space in Linux

Increase system performance by adding swap space in Linux.

In case you are falling short of swap space on a linux server, follow below steps to add more swap space.


Create swap file


Use linux dd command to create a swap file under root directory (/swapfile1)

Add 4gb swap file
-----------------
dd if=/dev/zero of=/swapfile1 bs=1024 count=4194304

Add 20gb swap file
------------------
dd if=/dev/zero of=/swapfile1 bs=1024 count=20971520

Note: formula to calculate count = 1024 * (swap size in MB)

  • For 1 GB of swap. count = 1024 * 1024 = 1048576

  • For 2 GB of swap. count = 2048 * 1024 = 2097152

  • For 4 GB of swap. count = 4096 * 1024 = 4194304

Give permissions

chmod 0600 /swapfile1
mkswap /swapfile1
swapon /swapfile1

Add to /etc/fstab

vi /etc/fstab

/swapfile1 swap swap defaults 0 0

Check swap space

cat /proc/swaps

Become a top notch dba.png
bottom of page