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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. CentOS / RHEL 7 : How to enable telnet for a group of users
  2. Configuring Network Redundancy for PaceMaker Cluster Communication
  3. How to Check whether SELinux is Enabled or Disabled
  4. How to enable core dump for Applications on CentOS/RHEL
  5. Passwordless SSH not working for local users on LDAP servers – CentOS/RHEL 7
  6. How to enable IPv6 on CentOS / RHEL 6
  7. How to enable CUPS Debugging on CentOS/RHEL
  8. CentOS / RHEL 5 : How to configure Interface bonding (NIC teaming)
  9. Linux OS Service ‘lm_sensors’
  10. showmount Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • How to disable ACPI in CentOS/RHEL 7
  • How to Use real-time query to access data on a physical standby database
  • CentOS/RHEL 8: “ACPI MEMORY OR I/O RESET_REG” Server Hung after reboot
  • How to Create a Physical Standby Database by Using SQL and RMAN Commands
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary