User Tools

Site Tools


ubuntu:swap:reduce_swap_on_an_lvm2_logical_volume

Ubuntu - Swap - Reduce Swap on an LVM2 Logical Volume

Sometimes it can be prudent to reduce swap space after installation.

For example, say you downgraded the amount of RAM in your system from 1 GB to 512 MB, but there is 2 GB of swap space still assigned.

  • It might be advantageous to reduce the amount of swap space to 1 GB, since the larger 2 GB could be wasting disk space.

You have three options:

  1. remove an entire LVM2 logical volume used for swap, or
  2. remove a swap file, or
  3. reduce swap space on an existing LVM2 logical volume.

Determine the name of the swap logical volume

lvs

returns:

  LV       VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  backup   vg01 -wi-ao----  3.72g                                                    
  home     vg01 -wi-ao---- 11.86g                                                    
  opt      vg01 -wi-ao----  1.86g                                                    
  root     vg01 -wi-ao----  3.86g                                                    
  sharewiz vg01 -wi-ao----  9.86g                                                    
  srv      vg01 -wi-ao---- 90.86g                                                    
  swap     vg01 -wi-ao----  4.00g                                                    
  usr      vg01 -wi-ao----  3.86g                                                    
  var      vg01 -wi-ao----  6.86g   

Reduce an LVM2 swap logical volume

Disable swapping for the associated logical volume:

swapoff -v /dev/mapper/vg01-swap

Reduce the LVM2 logical volume by 512 MB:

lvm lvreduce /dev/mapper/vg01-swap -L -512M

Format the new swap space

mkswap /dev/mapper/vg01-swap

Enable the extended logical volume

swapon -va

Test that the logical volume has been reduced properly

cat /proc/swaps # free

returns:

Filename				Type		Size	Used	Priority
/dev/dm-1                               partition	4198396	0	-1

Show your free swap space

free -tm | grep -i swap

returns:

Swap:          4099           0        4099
ubuntu/swap/reduce_swap_on_an_lvm2_logical_volume.txt · Last modified: 2024/07/30 15:01 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki