• 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 extend an LVM swap partition in Linux

By admin

Question: Given an LVM partition, how can we extend it to give some addtional space?

Swap filesystem

Swap is used if there is not enough memory available for your application. It’s normal and can be a good thing for Linux systems to use swap, even if there is still available RAM. But, it’s not just used if there is not enough memory.

How to extend LVM based swap filesystem

To increase the space for LVM Swap partition follow the steps given below:

1. Verify availability of the new space.

# fdisk -l /dev/sda
Disk /dev/sda: 4294 MB, 4294967296 bytes, 8388608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 byte

2. Create additional partition for the new swap partition.

# fdisk /dev/sda
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.
Device does not contain a recognized partition table

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-8388607, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607): 4056
Partition 1 of type Linux and of size 1004.5 KiB is set

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-8388607, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-8388607, default 8388607): 4056
Partition 1 of type Linux and of size 1004.5 KiB is set

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Understanding linux fdisk utility
Linux / UNIX : How to create primary partition using fdisk

3. Activate the new partition.

# partprobe

4. Verify the new partition is available.

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 12G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 11.5G 0 part
├─vg_lv_root (dm-0) 251:0 0 10.3G 0 lvm /
└─vg_lv_swap (dm-1) 251:1 0 1.2G 0 lvm [SWAP]
└─sda3 8:3 0 1G 0 part

sr0 11:0 1 1024M 0 rom

Note: a reboot may be needed if the change does not show at this point.

5. Create a new physical volume on the LUN.

# pvcreate /dev/sda3

6. Add the new volume to the volume group for the swap volume. Our examples use SwapVG and /dev/sda3; replace with the volume names and devices as appropriate to your deployment.

# vgextend SwapVG /dev/sda3

7. Disable swapping for the associated physical volume.

# swapoff -v /dev/SwapVG/SwapLV

8. Resize the logical volume to the desired size.

# lvresize /dev/SwapVG/SwapLV -L +8G

9. Format the extended swap volume.

# mkswap /dev/SwapVG/SwapLV

10. Enable the logical volume.

# swapon -va

11. View the new swap size.

# cat /proc/swaps
Filename Type Size Used Priority
/dev/dm-1 partition 1257468 0 -1
# free
total used free shared buffers cached
Mem: 1784432 196920 1587512 516 12624 77268
-/+ buffers/cache: 107028 1677404
Swap: 1257468 0 1257468

Filed Under: Linux

Some more articles you might also be interested in …

  1. Beginners Guide to Automounting File Systems in CentOS / RHEL
  2. Understanding linux fdisk utility
  3. How to Migrate CentOS/RHEL 6 iptables Rules to CentOS/RHEL 7 firewalld
  4. XFS error: Unable to mount filesystem With Noacl Permission in CentOS/RHEL 7
  5. What is the difference between & (ampersand) and && (double ampersand) while executing simultaneous commands on Linux
  6. Manage ASM Audit Files with syslog – configure lograte and auditing
  7. Troubleshooting “connection refused” From Remote Servers in CentOS/RHEL 7 (Either Firewalld or iptables service issue)
  8. CentOS / RHEL 7 : How to disable Transparent Huge pages (THP)
  9. How to Enable/Disable CPUs (Limiting CPU count) in CentOS / RHEL
  10. CentOS / RHEL 5,6 : How to Change the timezone

You May Also Like

Primary Sidebar

Recent Posts

  • What are Command Rules in oracle Database
  • Using Rule Sets in Oracle Database Vault
  • How Realms Work in Oracle Database Vault
  • How to use Privilege Analysis in Oracle Database
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary