How to increase swap memory size in linux

Steps to increase swap memory size:

Ensure swap memory size by issuing the following command.
[root@centos ~]# free -m
total used free shared buffers cached
Mem: 483 475 7 0 1 283
-/+ buffers/cache: 190 292
Swap: 511 242 269

 

Following command will create swap file with 2 GB space.
[root@centos ~]# dd if=/dev/zero of=/swapfile11 bs=1024 count=2097152
2097152+0 records in
2097152+0 records out
2147483648 bytes (2.1 GB) copied, 44.022 s, 48.8 MB/s

 

mkswap command sets up a Linux swap area on a device or in a file.
[root@centos ~]# mkswap /swapfile11
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=4d6e7614-0d03-43ce-b699-0d7f85ef313f

 

swapon command enable devices and files for paging and swapping.
[root@centos ~]# swapon /swapfile11

 

Ensure swap memory size again by issuing the following command.
[root@centos ~]# free -m
total used free shared buffers cached
Mem: 483 476 7 0 1 281
-/+ buffers/cache: 192 290
Swap: 2559 242 2317

 

If you want to make this change persistent for the future then make the following changes in ‘/etc/fstab’ file.
[root@centos ~]# vi /etc/fstab
/swapfile11 swap swap defaults 0 0

 

Swap size has been increased successfully.

***********************************************************************

Note: Please don’t hesitate to revert in case of any query OR feedback.

Thanking you.
Have a easy life ahead.

This entry was posted in Linux and tagged .

Leave a Reply