Increasing SWAP memory for better server performance is needed always when you have chosen incorrect SWAP size during server build or it’s a demand of memory intensive application. This tutorial will tell you how to increase SWAP memory in Redhat Linux 7 or CentOs7.
There are two types of SWAP viz. partition and file type. And in this tutorial, we will add a partition type of SWAP taking a new disk. If you already have space in your server, you can also make file type SWAP.
Increasing SWAP in RHEL 7
1. Add new a disk to your server, it may be through SAN or through Vmware virtual pool. You can use our tutorial to scan your newly added disk online on the server.
Recommended Article: How to Safely Remove vmdk from Linux Virtual Host
2. Now create SWAP partition from the newly added disk using the below commands.
[root@localhost ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x989078c0. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-2097151, default 2048): ENTER Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): ENTER Using default value 2097151 Partition 1 of type Linux and of size 1023 MiB is set Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 82 Changed type of partition 'Linux' to 'Linux swap / Solaris' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# partx -a /dev/sdb partx: /dev/sdb: error adding partition 1 [root@localhost ~]# partx -a /dev/sdb partx: /dev/sdb: error adding partition 1
You can verify your newly created SWAP partition by using fdisk command as below.
[root@localhost ~]# fdisk -l /dev/sdb Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x989078c0 Device Boot Start End Blocks Id System /dev/sdb1 2048 2097151 1047552 82 Linux swap / Solaris
3. Now format this newly created partition as SWAP using mkswap command.
[root@localhost ~]# mkswap /dev/sdb1 Setting up swapspace version 1, size = 1047548 KiB no label, UUID=4a28616d-065f-4123-b801-97d2b25019b7
4. After formatting the disk with SWAP, you will have to enable the SWAP with swapon command and then you can verify it.
[root@localhost ~]# swapon /dev/sdb1 [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/dm-0 partition 524284 0 -1 /dev/sdb1 partition 1047548 0 -2 [root@localhost ~]#
5. Now to make newly added SWAP memory to be available at next boot, put its entry in fstab file like below.
UUID=4a28616d-065f-4123-b801-97d2b25019b7 swap swap defaults 0 0
This is how you can increase or add SWAP memory in Linux 7 server easily. If you have any issue in performing this task, then please leave your comments below. We will be happy to help you. You can also drop email to us or leave your question in our Facebook page.
If you like the article, do like and share it. You can also subscribe to Storage Tutorials by Email for more such interesting tutorials.
Im trying to increase a swap partition from 8G to 16G and it says insufficient free space
Sorry for late reply. Can you please tell what are you doing. Did you created separate partition for SWAP?
For me the uuid attempt failed to mount. Indeed when i used /dev/sdb1 after the reboot swap was active. The commented entry was pasted from blkid, so it wasn’t a typo. What was wrong?
/dev/mapper/cl-root / xfs defaults 0 0
UUID=dfb824a4-6496-45a4-8505-0c6cdf41b732 /boot xfs defaults 0 0
/dev/mapper/cl-swap swap swap defaults 0 0
#UUID=3c3ad09a-050f-447f-87a5-210923012951 swap swap defaults 0 0
/dev/sdb1 swap swap defaults 0 0
Hi Alex.
That’s very strange thing and it should not happen. Did you used correct UUID?