LVM: Extend SWAP size by adding a new Logical Volume

LVM: Extend SWAP size by adding a new Logical Volume

# Tested on RHEL 5, 6 & 7

# Adding a file to swap space is not a common operation so we will focus on adding a LV


# Check current swap volume(s) 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




# Create a new Logical Volume, preferably on system VG, that will be dedicated to swap space

# We will extend swap by adding a 1 GB Logical Volume

# 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  23
  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


# Create new LV

root@<server>:/#> lvcreate -L 1GB -n newswaplv rvg
  Logical volume "newswaplv" created


# Check LV

root@<server>:/#> lvdisplay /dev/rvg/newswaplv
  --- Logical volume ---
  LV Name                /dev/rvg/newswaplv
  VG Name                rvg
  LV UUID                gf2IqR-kRMj-vMnJ-VCH3-N0gh-UxoG-AWX6Xu
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                1.00 GB
  Current LE             32
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:6



# Set up the new swap area

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



# Enable swapping on new LV

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



# Check final size and partitions being used by swap

root@<server>:/#> free
             total       used       free     shared    buffers     cached
Mem:      11508864    4664996    6843868          0     432464    3786168
-/+ buffers/cache:     446364   11062500
Swap:     15400944          0   15400944                                       <----


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



# Add following line to /etc/fstab for the LV to be automatically mounted as swap
# during system startup

/dev/rvg/newswaplv         swap                    swap    defaults        0 0
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
OpenSSL – sprawdzanie czy klucz pasuje do certyfikatu
Viewed 2049 times since Thu, May 24, 2018
Secure Remote Logging to Central Log Server Using RSYSLOG on CentOS 6 / CentOS 7 and stunnel
Viewed 2647 times since Sun, Dec 6, 2020
Open SSL Encrypt & Decrypt Files With Password Using OpenSSL
Viewed 5369 times since Mon, Feb 18, 2019
Use inotify-tools on CentOS 7 or RHEL 7 to watch files and directories for events
Viewed 13001 times since Fri, Jul 27, 2018
OEL 7 – How to disable IPv6 on Oracle Linux 7 – Follow Up
Viewed 8763 times since Wed, Jul 25, 2018
HOWTO: Use SSL/port 465 in smarthost stunnel
Viewed 3038 times since Fri, Sep 28, 2018
CentOS / RHEL : How to move a Volume Group from one system to another
Viewed 2535 times since Mon, Jan 28, 2019
Creating SWAP partition using FDISK & FALLOCATE commands
Viewed 1931 times since Thu, Jan 16, 2020
Linux Add a Swap File – HowTo
Viewed 9586 times since Fri, Jun 8, 2018
How to recover error - Audit error: dispatch err (pipe full) event lost
Viewed 20516 times since Tue, Aug 6, 2019