====== 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:
- remove an entire LVM2 logical volume used for swap, or
- remove a swap file, or
- 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