Add swap space to our logical volume group

Increase your LVM space

  • if need add some space to LVM by following this link.

Adding Swapspace to a LVM

 

Verify the current status 
# free
             total       used       free     shared    buffers     cached
Mem:       4321648     580520    3741128          0      34332     195128
-/+ buffers/cache:     351060    3970588
Swap:      2064380          0    2064380

# pvs
  PV         VG       Fmt  Attr PSize  PFree
  /dev/sda2  vg_oel64 lvm2 a--  40.34g    0 
  /dev/sda3           lvm2 a--   6.04g 6.04g

# swapon -s
Filename                Type        Size    Used    Priority
/dev/dm-1                               partition    2064380    0    -1

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_oel64/lv_root
  LV Name                lv_root
  VG Name                vg_oel64
  LV UUID                iSIBzr-Vfsk-YrXP-1yzX-2kwS-3g5L-GCIgYb
  LV Write Access        read/write
  LV Creation host, time oel64.example.com, 2013-09-06 13:26:38 +0200
  LV Status              available
  # open                 1
  LV Size                38.37 GiB
  Current LE             9823
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
  --- Logical volume ---
  LV Path                /dev/vg_oel64/lv_swap
  LV Name                lv_swap
  VG Name                vg_oel64
  LV UUID                Owo3gj-FEgp-7cXS-hT82-Guvp-WpDE-v0hHEZ
  LV Write Access        read/write
  LV Creation host, time oel64.example.com, 2013-09-06 13:26:46 +0200
  LV Status              available
  # open                 2
  LV Size                1.97 GiB
  Current LE             504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

Extent logical volume  /dev/vg_oel64/lv_swap    
# lvextend -L+1G  /dev/vg_oel64/lv_swap
  Extending logical volume lv_swap to 2.97 GiB
  Insufficient free space: 256 extents needed, but only 0 available

# vgdisplay
  --- Volume group ---
  VG Name               vg_oel64
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               40.34 GiB
  PE Size               4.00 MiB
  Total PE              10327
  Alloc PE / Size       10327 / 40.34 GiB
  Free  PE / Size       0 / 0   
  VG UUID               gLVoNb-bIGA-rZZq-pfh9-w6db-ToTC-HSRaPw

Add our newly created partition to Volume group "vg_oel64  
# vgextend vg_oel64 /dev/sda3
  Volume group "vg_oel64" successfully extended
# pvscan
  PV /dev/sda2   VG vg_oel64   lvm2 [40.34 GiB / 0    free]
  PV /dev/sda3   VG vg_oel64   lvm2 [6.04 GiB / 6.04 GiB free]
  Total: 2 [46.38 GiB] / in use: 2 [46.38 GiB] / in no VG: 0 [0   ]
# pvs
  PV         VG       Fmt  Attr PSize  PFree
  /dev/sda2  vg_oel64 lvm2 a--  40.34g    0 
  /dev/sda3           lvm2 a--   6.04g 6.04g
# lvdisplay /dev/vg_oel64/lv_swap
  --- Logical volume ---
  LV Path                /dev/vg_oel64/lv_swap
  LV Name                lv_swap
  VG Name                vg_oel64
  LV UUID                Owo3gj-FEgp-7cXS-hT82-Guvp-WpDE-v0hHEZ
  LV Write Access        read/write
  LV Creation host, time oel64.example.com, 2013-09-06 13:26:46 +0200
  LV Status              available
  # open                 2
  LV Size                1.97 GiB
  Current LE             504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

Add some space in 1GByte steps to our lv_swap volume group 
# lvextend -L+1G  /dev/vg_oel64/lv_swap
# lvextend -L+1G  /dev/vg_oel64/lv_swap
# lvextend -L+1G  /dev/vg_oel64/lv_swap
# pvs
  PV         VG       Fmt  Attr PSize  PFree
  /dev/sda2  vg_oel64 lvm2 a--  40.34g    0 
  /dev/sda3  vg_oel64 lvm2 a--   6.04g 3.04g 

Recreate swap device
Disable swapping for the associated logical volume:
# swapoff -v /dev/vg_oel64/lv_swap
swapoff on /dev/vg_oel64/lv_swap

Format the new swap space:
# mkswap  /dev/vg_oel64/lv_swap
mkswap: /dev/vg_oel64/lv_swap: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 5210108 KiB
no label, UUID=031c859f-0eef-43f2-a11d-75143f15b6eb

Add the volume for swap space usage and verify swap space
# swapon /dev/vg_oel64/lv_swap
# swapon -s
Filename                Type        Size    Used    Priority
/dev/dm-1                               partition    5210108    0    -1
# free
             total       used       free     shared    buffers     cached
Mem:       4321648     585744    3735904          0      35632     196636
-/+ buffers/cache:     353476    3968172
Swap:      5210108          0    5210108

Verify that  /dev/dm-1 pointing to our newly created newly create logical volume  vg_oel64/lv_swap:
# ls -l /dev/mapper | grep dm-1
lrwxrwxrwx. 1 root root       7 Sep  8 12:27 vg_oel64-lv_swap -> ../dm-1
# lvdisplay  /dev/vg_oel64/lv_swap
  --- Logical volume ---
  LV Path                /dev/vg_oel64/lv_swap
  LV Name                lv_swap
  VG Name                vg_oel64
  LV UUID                Owo3gj-FEgp-7cXS-hT82-Guvp-WpDE-v0hHEZ
  LV Write Access        read/write
  LV Creation host, time oel64.example.com, 2013-09-06 13:26:46 +0200
  LV Status              available
  # open                 2
  LV Size                4.97 GiB
  Current LE             1272
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

3 thoughts on “Add swap space to our logical volume group”

  1. Howdy very good web-site! Person. Exceptional. Outstanding. I will search for your web site and use the bottles also? I am grateful to locate a number of helpful information the following inside the submit, we would like determine excess strategies about this consideration, we appreciate you giving.

Leave a Reply

Your email address will not be published. Required fields are marked *