How To Create/Extend Swap Partition In Linux Using LVM
======
We are using LVM for flexible volume management so, why can’t we use LVM for swap space?
This allow users to increase the swap partition whenever we need.
If you upgraded the RAM in your system, it is necessary to add more swap space.
This help you to manage the system that run applications that require a large amount of memory.
Swap can be created in three ways
* Create a new swap partition
* Create a new swap file
* Extend swap on an existing logical volume (LVM)
It’s recommended to create a dedicated swap partition instead of swap file.
**Suggested Read :**
**(#)** [3 Easy Ways To Create Or Extend Swap Space In Linux][1]
**(#)** [Automatically Create/Remove And Mount Swap File In Linux Using Shell Script][2]
What is the recommended swap size in Linux?
### What Is Swap Space
Swap space in Linux is used when the amount of physical memory (RAM) is full. When physical RAM is full, inactive pages in memory are moved to the swap space.
This helps system to run the application continuously but it’s not considered a replacement for more RAM.
Swap space is located on hard drives so, it would not processing the request like physical RAM.
### How To Create A Swap Partition Using LVM
As we already know how to create logical volume do the same for swap as well. Just follow the below procedure.
Create a logical volume which you required. In my case i’m going to create `5GB` of swap partition.
```
$ sudo lvcreate -L 5G -n LogVol_swap1 vg00
Logical volume "LogVol_swap1" created.
```
Format the new swap space.
```
$ sudo mkswap /dev/vg00/LogVol_swap1
Setting up swapspace version 1, size = 5 GiB (5368705024 bytes)
no label, UUID=d278e9d6-4c37-4cb0-83e5-2745ca708582