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
Manage SSH Key File With Passphrase
Viewed 2185 times since Tue, Mar 5, 2019
Red Hat Cluster Tutorial
Viewed 1973 times since Sun, Jun 3, 2018
RHEL: Scan and configure new SAN (fibre channel) LUNs
Viewed 7906 times since Sun, May 27, 2018
Linux - How to get network speed and statistic of ethernet adapter in Linux
Viewed 2062 times since Fri, Jun 8, 2018
10 Linux cryptsetup Examples for LUKS Key Management (How to Add, Remove, Change, Reset LUKS encryption Key)
Viewed 5043 times since Tue, Jul 31, 2018
How To Create a Linux Swap File
Viewed 2359 times since Fri, Jun 8, 2018
Przekazywanie portów TCP rinetd
Viewed 43399 times since Thu, May 24, 2018
15 Linux Yum Command Examples – Install, Uninstall, Update Packages
Viewed 3248 times since Thu, Oct 25, 2018
How to enable Proxy Settings for Yum Command on RHEL / CentOS Servers
Viewed 12346 times since Thu, Jul 19, 2018
20 Linux YUM (Yellowdog Updater, Modified) Commands for Package Management YUM
Viewed 11163 times since Thu, Oct 25, 2018