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
6 easy steps to setup offline two factor authentication in Linux
Viewed 13221 times since Mon, Apr 6, 2020
Red Hat Enterprise Linux - Allow Root Login From a Specific IP Address Only
Viewed 2897 times since Wed, Oct 3, 2018
RHEL7: How to get started with Firewalld.
Viewed 12184 times since Wed, May 22, 2019
RHEL7: Create and configure LUKS-encrypted partitions and logical volumes to prompt for password and mount a decrypted file system at boot.
Viewed 12750 times since Mon, Aug 6, 2018
Install OpenVPN On CentOS / RHEL 7
Viewed 3109 times since Fri, May 15, 2020
red hat 7 tmpfiles service
Viewed 1893 times since Thu, Oct 11, 2018
Script to Offline and Remove A Disk In Linux
Viewed 2024 times since Mon, Jan 28, 2019
UUIDs and Linux: Everything you ever need to know [Update]
Viewed 5012 times since Tue, Jul 17, 2018
Manage Linux Password Expiration and Aging Using chage
Viewed 4721 times since Tue, Sep 11, 2018
Linux An introduction to swap space on Linux systems
Viewed 2512 times since Thu, Jan 23, 2020