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
SSH: Execute Remote Command or Script – Linux
Viewed 2207 times since Mon, Feb 18, 2019
RHEL: How to change a USER/GROUP UID/GID and all owned files
Viewed 20878 times since Sat, Jun 2, 2018
How to sort IP addresses in Linux
Viewed 3399 times since Sun, May 20, 2018
RHCS: Configure an active/backup pacemaker cluster
Viewed 8798 times since Sun, Jun 3, 2018
Need to set up yum repository for locally-mounted DVD on Red Hat Enterprise Linux 7
Viewed 2903 times since Mon, Oct 29, 2018
RHEL7: Configure automatic updates.
Viewed 1726 times since Wed, Oct 17, 2018
Increase A VMware Disk Size (VMDK) Formatted As Linux LVM without rebooting
Viewed 15185 times since Wed, May 30, 2018
Df command in Linux not updating actual diskspace, wrong data
Viewed 2713 times since Wed, May 30, 2018
RHEL: Rename a network interface on RHEL 7
Viewed 10244 times since Sat, Jun 2, 2018
Terminal based "The Matrix" like implementation
Viewed 2053 times since Thu, Apr 18, 2019