Step 1: Check current swap space in OS
[root@rhel7 ~]# free -m
total used free shared buffers cached
Mem: 987 805 181 13 0 353
-/+ buffers/cache: 451 535
Swap: 2047 0 2047
[root@rhel7 ~]#
Step 2: Now check disk space we will create swap space and necessary action
[root@rhel7 ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000aab0f
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 21506047 10240000 83 Linux
/dev/sda3 21506048 25700351 2097152 82 Linux swap / Solaris
/dev/sda4 25700352 41943039 8121344 5 Extended
/dev/sda5 25702400 40038399 7168000 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x44245958
Device Boot Start End Blocks Id System
Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 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: 0x6cba2f17
Device Boot Start End Blocks Id System
[root@rhel7 ~]#
Note: Here we will consider /dev/sdc for swap partition
[root@rhel7 ~]# fdisk /dev/sdc
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.
Command (m for help): n [For new partition creation]
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): [Primary partition]
Using default response p
Partition number (1-4, default 1):
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): +500M [500MB Partition size]
Partition 1 of type Linux and of size 500 MiB is set
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 82 [82 code for Linux swap partition]
Changed type of partition 'Linux' to 'Linux swap / Solaris'
Command (m for help): p [Print partition info of /dev/sdc]
Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 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: 0x6cba2f17
Device Boot Start End Blocks Id System
/dev/sdc1 2048 1026047 512000 82 Linux swap / Solaris
Command (m for help): w [Write and save new partition]
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@rhel7 ~]#
Step 3: Inform the OS of partition table changes
Step 4: Now setup this newly created partition as swap area using the mkswap command
[root@rhel7 ~]# mkswap /dev/sdc1
mkswap: /dev/sdc1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 511996 KiB
no label, UUID=5fe81d10-f220-4572-80b3-56f65addefb2
[root@rhel7 ~]
[root@rhel7 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Dec 20 10:52:45 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=3861c2f0-4524-4b79-83bf-75be5412b10b / xfs defaults 1 1
UUID=90c2e689-ad4e-4c54-a470-f6dffa4be07d /boot xfs defaults 1 2
UUID=2cd6288f-86f3-4feb-ae99-e77642c0d205 /data xfs defaults 1 2
UUID=f5c7ed53-48b9-48e0-b47d-527bf7bb88fa swap swap defaults 0 0
UUID="5fe81d10-f220-4572-80b3-56f65addefb2" swap swap defaults 0 0
[root@rhel7 ~]#
Step 5: Enable the swap partition for usage using swapon command as shown below.
[root@rhel7 ~]# swapon /dev/sdc1
Step 6: Now check swap space added or not
[root@rhel7 ~]# free -m
total used free shared buffers cached
Mem: 987 882 104 7 1 354
-/+ buffers/cache: 526 460
Swap: 2547 0 2547
[root@rhel7 ~]#
Verify whether the newly created swap area is available for your use.
Filename Type Size Used Priority
/dev/sda3 partition 2097148 0 -1
/dev/sdc1 partition 511996 0 -2
[root@rhel7 ~]#