Extending Swap in LVM

Sometimes I need to extend swap in an environment managed by LVM. Here are the commands you need to do so.

In this case we want to increase swap to 6 gigabytes. Initially just check the status of swap.

$ cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       4169724 5432    -2
$ free
              total        used        free      shared  buff/cache   available
Mem:        3825732      496600      220612      176516     3108520     2863696
Swap:       4169724        5432     4164292

Next, disable swap, increase it, and add it back to the system.

# swapoff -v /dev/mapper/vg00-swap
swapoff /dev/mapper/vg00-swap
# lvresize /dev/mapper/vg00-swap -L +2G
  Size of logical volume vg00/swap changed from 3.98 GiB (1019 extents) to 5.98 GiB (1531 extents).
  Logical volume vg00/swap successfully resized.
# mkswap /dev/mapper/vg00-swap
mkswap: /dev/mapper/vg00-swap: warning: wiping old swap signature.
Setting up swapspace version 1, size = 6 GiB (6421475328 bytes)
no label, UUID=ac8eaa77-0a11-43b2-b39c-eed88f3b53e1
# swapon -va
swapon: /dev/mapper/vg00-swap: found signature [pagesize=4096, signature=swap]
swapon: /dev/mapper/vg00-swap: pagesize=4096, swapsize=6421479424, devsize=6421479424
swapon /dev/mapper/vg00-swap

Finally, run the first commands again to see the new size.

# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       6270972 0       -2
# free
              total        used        free      shared  buff/cache   available
Mem:        3825756      409348     2927156       17440      489252     3170928
Swap:       6270972           0     6270972
This entry was posted in Computers, Troubleshooting and tagged , , , , , . Bookmark the permalink.

Leave a Reply

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