LVM: Extend SWAP size by growing existing Logical Volume

LVM: Extend SWAP size by growing existing Logical Volume

# Tested on RHEL 5, 6 & 7

# Check which is the swap volume and its size

root@<server>:/#> cat /etc/fstab | grep swap
/dev/rvg/swaplv         swap                    swap    defaults        0 0


root@<server>:/#> lvdisplay /dev/rvg/swaplv
  --- Logical volume ---
  LV Name                /dev/rvg/swaplv
  VG Name                rvg
  LV UUID                m0EThc-4Epd-Ecj3-lvPK-BfU0-D98H-1pgyRY
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                13.69 GB
  Current LE             438
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:5


root@<server>:/#> free -m
             total       used       free     shared    buffers     cached
Mem:         11239       4556       6682          0        422       3697
-/+ buffers/cache:        436      10802
Swap:        14015          0      14015                                       <----


root@<server>:/#> cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/mapper/rvg-swaplv                  partition       14352376        0       -3



# Disable swapping on LV to be resized (in our case, as we have a single LV allocated to swap, we could
# run command with '-a' flag so swapping is disabled on all known swap devices and files - as found in
# /proc/swaps or /etc/fstab)

# root@<server>:/#> swapoff -a

root@<server>:/#> swapoff /dev/rvg/swaplv



# Check that swapping has been disabled

root@<server>:/#> free
             total       used       free     shared    buffers     cached
Mem:      11508864    4657932    6850932          0     432268    3786136
-/+ buffers/cache:     439528   11069336
Swap:            0          0          0                                       <----




# Extend swap Logical Volume (we will add 1 GB)


# Verify that there is enough space on VG

root@<server>:/#> vgdisplay /dev/rvg
  --- Volume group ---
  VG Name               rvg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  21
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                6
  Open LV               6
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               136.50 GB
  PE Size               32.00 MB
  Total PE              4368
  Alloc PE / Size       1718 / 53.69 GB
  Free  PE / Size       2650 / 82.81 GB                                         <----
  VG UUID               2TkcmU-Uzys-Znql-aXqx-pr2D-O8dk-oWsOlL



# Extend LV

root@<server>:/#> lvextend -L +1GB /dev/rvg/swaplv
  Extending logical volume swaplv to 14.69 GB
  Logical volume swaplv successfully resized



# Set up the new swap area

root@<server>:/#> mkswap /dev/rvg/swaplv
Setting up swapspace version 1, size = 15770578 kB



# Enable swapping on resized LV (in our case, as we have a single LV allocated to swap, we could
# run command with '-a' flag so swapping is enabled on all known swap devices and files (as found
# in /proc/swaps or /etc/fstab)


# root@<server>:/#> swapon -a


root@<server>:/#> swapon /dev/rvg/swaplv



# Check final size

root@<server>:/#> free
             total       used       free     shared    buffers     cached
Mem:      11508864    4664192    6844672          0     432284    3786136
-/+ buffers/cache:     445772   11063092
Swap:     15400952          0   15400952                                       <----
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Inxi – A Powerful Feature-Rich Commandline System Information Tool for Linux
Viewed 18942 times since Sat, Jun 2, 2018
RHEL: Extending the maximum inode count on a ext2/ext3/ext4 filesystem
Viewed 3280 times since Sun, May 27, 2018
How To Run Multiple SSH Command On Remote Machine And Exit Safely
Viewed 4349 times since Tue, Aug 6, 2019
logrotate Understanding logrotate utility
Viewed 1838 times since Sun, Jan 12, 2020
bash mistakes This page is a compilation of common mistakes made by bash users. Each example is flawed in some way.
Viewed 9127 times since Sun, Dec 6, 2020
ZPOOL: Detach a submirror from a mirrored zpool
Viewed 2717 times since Sun, Jun 3, 2018
How to remove CTRL-M (^M) characters from a file in Linux
Viewed 2627 times since Thu, Feb 7, 2019
Red Hat 8 How to Set Up Automatic Updates for CentOS 8
Viewed 3770 times since Fri, Sep 25, 2020
Using Kerberos security with Server for NFS
Viewed 9721 times since Wed, Jun 27, 2018
How To Use the Linux Auditing System on CentOS 7
Viewed 3979 times since Fri, Apr 5, 2019