How to extend Swap space in Logical Volume

1. Find out the name of the swap logical volume using the "lvs" command

[root@hostname ~]# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

lv_download vg_hostname -wi-ao---- 200.00g

lv_holding vg_hostname -wi-ao---- 200.00g

lv_home vg_hostname -wi-ao---- 4.88g

lv_opt vg_hostname -wi-ao---- 29.49g

lv_root vg_hostname -wi-ao---- 5.08g

lv_swap vg_hostname -wi-ao---- 4.00g

lv_tmp vg_hostname -wi-ao---- 4.98g

lv_usr vg_hostname -wi-ao---- 4.98g

lv_var vg_hostname -wi-ao---- 9.96g

2. Find out LV path for swap logical volume

[root@hostname ~]# lvdisplay

--- Logical volume ---

LV Path /dev/vg_hostname/lv_swap

LV Name lv_swap

VG Name vg_hostname

LV UUID IhGUco-xoJp-zQ6S-o8iw-ivdc-fHWE-XS3zI2

LV Write Access read/write

LV Creation host, time hostname.ipx.com, 2015-06-05 10:37:23 +0200

LV Status available

# open 1

LV Size 4.00 GiB

Current LE 1024

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:1

3. Turn off the swap partition

[root@hostname ~]# swapoff /dev/vg_hostname/lv_swap

4. Resize the swap partition, adding 12GB more space to it

[root@hostname ~]# lvresize -L+12G /dev/vg_hostname/lv_swap

Size of logical volume vg_hostname/lv_swap changed from 4.00 GiB (1024 extents) to 16.00 GiB (4096 extents).

Logical volume lv_swap successfully resized

5. Format the new swap space to make it usable

[root@hostname ~]# mkswap /dev/vg_hostname/lv_swap

mkswap: /dev/vg_hostname/lv_swap: warning: don't erase bootbits sectors

on whole disk. Use -f to force.

Setting up swapspace version 1, size = 16777212 KiB

no label, UUID=b6195773-eba1-4af7-aafc-466867757985

Turn the swap volume back on:

[root@hostname ~]# swapon /dev/vg_hostname/lv_swap

6. Check swap space

[root@hostname ~]# free -tom| grep -i swap

Swap: 16383 0 16383