How to add new swap partition on CentOS 7

For the purpose of this post, let’s assume that you do not have any swap configured on your system. /dev/sdc is the drive referenced with no partitions. Since we are going to make a single partition filling the disk, note that any data currently on that disk will be lost. Follow the steps given below to add /dev/sdc1 partition as the new swap partition on the system.


1. Use the fdisk command as root to create a swap partition.

# fdisk /dev/sdc


A new prompt will appear, type ‘p’ to display the current partitions. Verify that you do not have any existing partitions here.


To create a new swap partition type “n“. Since this will be the first partition make it primary by selecting ‘p‘. Select ‘1‘ for the partition number. To accept the default settings for the beginning sector, just press ‘enter’. On the next prompt enter a value of +2G to set the size of a swap partition.


On the next prompt, press ‘t‘ to change the partition type. Enter the number ‘1’, to change the partition that was just created

Type ‘82‘ and press enter. Type 82 is for swap partitions. Verify the results by checking the partition table by typing ‘p’. Type ‘w’ to write the changes made.


2. Reread the partition using the partprobe command for the kernel to see the newly created swap partition.

# partprobe


3. Create the swap association on the new device:

# mkswap /dev/sdc1
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=99e34f44-b366-4805-b290-614717f9058b


4. you can use UUID from the output of mkswap when creating the swap to add an entry in /etc/fstab. This entry ensures that the swap partition is activated after each reboot.

# vi /etc/fstab
UUID=99e34f44-b366-4805-b290-614717f9058b     swap     swap     defaults     0 0


5. Activate the swap partition:

# swapon -a


6. Verify it is present by executing:

# swapon -s
Filename				Type		Size	Used	Priority
/dev/sdc1                              	partition	2097148	0	-2
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How can I configure a ip range in CentOS7?

You have to use a range file Edit /etc/sysconfig/network-scripts/ifcfg-enp0s3 and make...

Adding a Public IPv6 Address to a Linux Server (CentOS 7)

To configure an additional public IPv6 address in CentOS 7, proceed as follows:...

How To Install EPEL Repository On CentOS And RHEL 7

How to install EPEL for Centos 7 [root@localhost ~]# cat  /etc/centos-release CentOS Linux...

Common Commands (CentOS 7)

Basic Configuration Query or System Locale...

Install LAMP Stack on CentOS 7

Install LAMP Stack on CentOS 7 One of the most simple and barebones solutions you can have for...