How To Reduce An LVM Swap Partition On CentOS 7 /RHEL 7

How To Reduce An LVM Swap Partition On CentOS 7 /RHEL 7

In this guide tutorial, we will cover how to reduce an lVM swap partition on a CentOS 7 / RHEL 7 server.

Task: Reduce the LVM Swap partition /dev/vg1/swap from 1.5 GiB to 1 GiB size

1. Step – Disable the LVM swapping Partition

– To disable swapping for the associated logical volume /dev/vg1/swap, run the following command as root:

[root@server ~]# swapoff -v /dev/vg1/swap
swapoff /dev/vg1/swap

2. Step Reduce the LVM logical volume

– To reduce the size of the LVM logical volume, run the following command

[root@server ~]# lvreduce /dev/vg1/swap -L -512M
  WARNING: Reducing active logical volume to 1.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce centos/swap? [y/n]: y
  Size of logical volume vg1/swap changed from 1.50 GiB (384 extents) to 1.00 GiB (256 extents).
  Logical volume vg1/swap successfully resized.

3. Step – Format the new Swap LVM logical volume

[root@server ~]# mkswap /dev/vg1/swap
mkswap: /dev/vg1/swap: warning: wiping old swap signature.
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=9d608205-2605-4129-8a9e-ae0d2a87f5fe

4. Step – Enable the Swap LVM logical volume

[root@server ~]# swapon -va
swapon /dev/mapper/vg1-swap
swapon: /dev/mapper/vg1-swap: found swap signature: version 1, page-size 4, same byte order
swapon: /dev/mapper/vg1-swap: pagesize=4096, swapsize=1073741824, devsize=1073741824

5. Step – Test and checking

– To that the logical volume has been reduced properly, use one of following commands:

[root@server ~]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       1048572 0       -1
[root@server ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           754M        105M        474M         16M        174M        478M
Swap:          1.0G          0B        1.0G

That’s it, hope you found this tutorial useful, until next time.

PS. If you like this post please share it with your friends on the social networks.Thanks.

Enjoyed this video?
How To Reduce An LVM Swap Partition On CentOS 7 /RHEL 7
"No Thanks. Please Close This Box!"