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
tcpdump
Viewed 8727 times since Fri, Jul 27, 2018
A Simple Guide to Oracle Cluster File System (OCFS2) using iSCSI on Oracle Cloud Infrastructure
Viewed 7669 times since Sat, Jun 2, 2018
Setting up encrypted tunnel using stunnel
Viewed 2138 times since Fri, Sep 28, 2018
Linux How to reset a root password on Fedora
Viewed 1972 times since Sun, Dec 6, 2020
Linux Proxy Server Settings – Set Proxy For Command Line
Viewed 2659 times since Mon, Feb 18, 2019
linux unix aix banner /etc/issue
Viewed 1711 times since Fri, Aug 3, 2018
List DNS records, nameservers of a domain from command line
Viewed 1687 times since Sun, Sep 30, 2018
debian Debian/Ubuntu Linux: Find If Installed APT Package Includes a Fix/Patch Via CVE Number
Viewed 9162 times since Sun, Sep 23, 2018
Create a Linux Swap File
Viewed 2668 times since Fri, Jun 8, 2018
Linux Cluster Tutorial
Viewed 1720 times since Sat, Sep 29, 2018