Increase or Decrease LV Swap in CentOS 6/RHEL 6

Scenario: How to increase or decrease swap space(logical volume swap) in CentOS 6/RHEL 6

System: CentOS 6/ RHEL 6

Steps increase Swap space
Example increase 1 GB swap space.

1) You must check the path of swap logical volume and the free space in the swap volume group before continue to step 2.
# free -m
# lvdisplay | grep swap
# vgs

[root@kucing ~]# free -m
 total used free shared buffers cached
Mem: 1877 405 1471 0 31 200
-/+ buffers/cache: 173 1703
Swap: 3071 0 3071
[root@kucing ~]# lvdisplay | grep swap
 LV Path /dev/vg_kucing/lv_swap
 LV Name lv_swap
[root@kucing ~]# vgs
 VG #PV #LV #SN Attr VSize VFree
 data_vg 1 1 0 wz--n- 9.31g 4.31g
 vg_data2 1 1 0 wz--n- 9.31g 1.31g
 vg_kucing 2 2 0 wz--n- 39.50g 10.00g
[root@kucing ~]#

2) From step 1 we got swap space is 3GB, the swap path and free size of the swap Volume Group,then continue disable swapping for the associated logical volume:
# swapoff -v /dev/vg_kucing/lv_swap

3) Resize the LVM2 logical volume by 2 GB:
# lvresize /dev/vg_kucing/lv_swap -L +1G

4) Format the new swap space:
# mkswap -f /dev/vg_kucing/lv_swap

5) Enable the extended logical volume:
# swapon -v /dev/vg_kucing/lv_swap

[root@kucing ~]# swapoff -v /dev/vg_kucing/lv_swap
swapoff on /dev/vg_kucing/lv_swap
[root@kucing ~]# lvresize /dev/vg_kucing/lv_swap -L +1G
 Size of logical volume vg_kucing/lv_swap changed from 3.00 GiB (768 extents) to 4.00 GiB (1024 extents).
 Logical volume lv_swap successfully resized.
[root@kucing ~]# mkswap -f /dev/vg_kucing/lv_swap
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=949221bf-97a6-4ed9-a908-2b931779e798
[root@kucing ~]# swapon -v /dev/vg_kucing/lv_swap
swapon on /dev/vg_kucing/lv_swap
swapon: /dev/mapper/vg_kucing-lv_swap: found swap signature: version 1, page-size 4, same byte order
swapon: /dev/mapper/vg_kucing-lv_swap: pagesize=4096, swapsize=4294967296, devsize=4294967296
[root@kucing ~]# free -m
 total used free shared buffers cached
Mem: 1877 405 1471 0 31 200
-/+ buffers/cache: 173 1704
Swap: 4095 0 4095
[root@kucing ~]#

Steps to decrease Swap space
Example decrease 1 GB swap space.

1) Check the path of swap logical volume.
# lvdisplay | grep swap

2) Disable swapping for the associated logical volume:
# swapoff -v /dev/vg_kucing/lv_swap

3) Reduce the LVM2 logical volume by 512 MB:
# lvreduce -L 1G /dev/vg_kucing/lv_swap

4) Format the new swap space:
# mkswap -f /dev/vg_kucing/lv_swap

5) Enable the extended logical volume:
# swapon -v /dev/vg_kucing/lv_swap

[root@kucing ~]# lvdisplay | grep swap
 LV Path /dev/vg_kucing/lv_swap
 LV Name lv_swap
[root@kucing ~]# swapoff -v /dev/vg_kucing/lv_swap
swapoff on /dev/vg_kucing/lv_swap
[root@kucing ~]# lvreduce -L 1G /dev/vg_kucing/lv_swap
 WARNING: Reducing active logical volume to 1.00 GiB.
 THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg_kucing/lv_swap? [y/n]: y
 Size of logical volume vg_kucing/lv_swap changed from 4.00 GiB (1024 extents) to 1.00 GiB (256 extents).
 Logical volume lv_swap successfully resized.
[root@kucing ~]# mkswap -f /dev/vg_kucing/lv_swap
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=7db2f5c6-09c7-467a-9f1b-4be3c2aac723
[root@kucing ~]# swapon -v /dev/vg_kucing/lv_swap
swapon on /dev/vg_kucing/lv_swap
swapon: /dev/mapper/vg_kucing-lv_swap: found swap signature: version 1, page-size 4, same byte order
swapon: /dev/mapper/vg_kucing-lv_swap: pagesize=4096, swapsize=1073741824, devsize=1073741824
[root@kucing ~]#

Leave a Reply

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