• 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

How to increase swap space on Linux

By admin

The Ask

The user wants to increase the swap space on their Linux machine (CentOS/RHEL). The existing swap space has been configured as an LVM logical Volume.

The Solution

The following solution will first add a new physical volume (PV) to the volume group being used, and will then extend the swap logical volume.

In the example below, the voljume group is called vg_main, the swap logical volume is called lv_swap, and the new physical volume is called /dev/xvdd. Please substitute the name of the physical volume you are adding when running these commands.

Please back up any configuration information and data from the VM instance before performing LVM commands, and if possible run through the procedure on a non-production system first.

Step 1 : Create the PV

First, create a new Physical Volume using the disk /dev/vxdd.

# pvcreate /dev/xvdd

Step 2 : Add PV to existing VG

Add the new PV to existing volume group to extend the available space.

# vgextend vg_main /dev/xvdd

This adds more space to the already existing vg_main volume group, so you can then extend an existing swap logical volume, or if you’ve already deleted it, create a new logical volume for the swap that is larger.

Step 3 : Extend LV

Extend the logical volume used for swap.

# lvextend -l +100%FREE /dev/vg_main/lv_swap

This command will extend lv_swap into the remaining space in vg_main.

Step 4 : Format swap space

Next step is to format the swap space using the “mksawp” command.

# mkswap /dev/mapper/vg_main/lv_swap

Step 5 : Add swap in /etc/fstab (optional if already added)

If the swap is not already added to /etc/fstab, add it to /etc/fstab.

# vi /etc/fstab
/dev/mapper/vg_swap-lv_swap    swap    swap    defaults    0 0

Step 6 : Activate VG and LV

Activate the volume groups and logical volumes:

# vgchange -ay

Step 7 : Activate the swap space

Mount the volumes and activate the swap space:

# mount -a
# swapon -s

Filed Under: Linux

Some more articles you might also be interested in …

  1. Understanding MySQL Privileges
  2. “iscsiadm” Discovery TimeOut With Two Or More Network Interfaces in CentOS/RHEL
  3. What is the purpose of utmp, wtmp and btmp files in Linux
  4. Extend volume on non-partitioned disk (XFS) under VMware guest
  5. DNS configuration file /etc/named.conf explained
  6. CentOS / RHEL : How to add swap file
  7. MySQL Server Error – “Can’t Create A New Thread (errno 11)”
  8. CentOS / RHEL : Installing and Configuring ASMLib
  9. How To Disable Or Extend System Logging Rate-limit on CentOS/RHEL 7
  10. What is the refid in ntpq -p output?

You May Also Like

Primary Sidebar

Recent Posts

  • How to set the default character set in MySQL and how to propagate it in a master-master replication scenario
  • “Connection reset by peer” – error while ssh into a CentOS/RHEL system with a specific user only
  • MySQL: how to figure out which session holds which table level or global read locks
  • Recommended Configuration of the MySQL Performance Schema
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary