Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells, Filesystems

Extending Swap on LVM2 Logical Volume

Submitted by on May 7, 2015 – 11:16 am

To grow swap on LVM you will need to temporarily disable the swap LV. This will leave without swap space, which may upset some applications (Oracle). So the first step should be to set up a temporary swap file on a filesystem with sufficient space.

root@oradb01a# free -m
             total       used       free     shared    buffers     cached
Mem:         64422      36865      27556          0        740      24164
-/+ buffers/cache:      11961      52461
Swap:         4095          0       4095

root@oradb01a# lvdisplay
...
  --- Logical volume ---
  LV Name                /dev/rootvg/swap
  VG Name                rootvg
  LV UUID                8nFs1I-9ilI-ZQPm-iKvx-6kCk-Ue8h-koUsdA
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                4.00 GB
...

In the example below we have a swap LV of 4GB currently in use. We need to grow it to 16GB. We will set up a temporary swap file in /opt:
dd if=/dev/zero of=/opt/swapfile bs=1024 count=4194304
mkswap /opt/swapfile
swapon /opt/swapfile

Now we will disable the LVM swap LV and grow it from 4GB to 16GB:
swapoff -v /dev/rootvg/swap
lvm lvresize /dev/rootvg/swap -L +12G
mkswap /dev/rootvg/swap
swapon -va

Finally, we will remove the temporary swap file:
swapoff -v /opt/swapfile
/bin/rm /opt/swapfile

And the result:
root@oradb01a# free
             total       used       free     shared    buffers     cached
Mem:      65968512   37982420   27986092          0     762420   24728500
-/+ buffers/cache:   12491500   53477012
Swap:     16777208          0   16777208

 

Print Friendly, PDF & Email

Leave a Reply