• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL : How to add new swap partition

by admin

Question

I have a new disk attached to the system. How can I create a new swap partition using this disk on the system?

Solution

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.

verify partition in fdisk

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 entre a value of +2G to set the size of swap partition.

create primary partition for swap CentOS RHEL

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.

set swap partition type CentOS RHEL in fdisk

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

Filed Under: CentOS/RHEL 4, CentOS/RHEL 5, CentOS/RHEL 6, CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. eject Command Examples in Linux
  2. Intel I219-LM Centos 6 network failed to start
  3. Yum Command – RPM Based Package Management Utility
  4. engrampa Command Examples in Linux
  5. What’s different between /bin/false and /sbin/nologin as nologin user’s shell
  6. btrbk Command Examples in Linux
  7. loadkeys Command Examples in Linux
  8. cpuid Command Examples in Linux
  9. How To Open A Port In CentOS / RHEL 7
  10. How to test a PHP script

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright