What Is Linux LVM (Logical Volume Management)?
Logical Volume Management used to create, manage and delete logical volumes in Linux operating systems. LVM provides RAID like architectures for disk drives. We can create single logical volume from multiple physical disks.
LVM consist of 3 main concepts:
- Physical Volumes
- Volume Groups
- Logical Volumes
Let me explain in a simple manner. By adding one or more than one Physical Volume we will create a Volume Group and than we can create one or more Logical Volume from a Volume Group. As we can see LVM provides some abstraction for disk and partition management.
PhysicalVolume1 + PhysicalVolume2 + ... + PhysicalVolumeN => Volume Group
Physical Volume is a physical disk or a partition which is the source of the storage. We can also use RAID disks or partitions. Physical volume will be added into Volume Groups and this will add more disk space to the Volume Groups.
Volume Groups a logical disk where one or more Physical Disk will participate. This will create enough disk space in order to create Logical Volumes.Volume groups provides flexibility like adding, removing physical volume , resizing Logical Volume on the fly.
Logical Volumes are the virtual disk or partitions created from a Volume Groups. We can resize and snapshot the Logical Volume without any interruption.
Create Volume Group
We will start by creating a Volume Group. First we will initialize the physical disk for the Volume Group. We will use
pvcreate command by providing the disk device.
$ sudo pvcreate /dev/sdb1
After the disk
sdb1 initialized we will create a volume Group named
myvg with the
$ sudo vgcreate myvg /dev/sdb1
Create Logical Volume
Than we will create Logical Volume with the
lvcreate command by providing the Volume Group and the Logical Volume name. In this example we will use
-n option for Logical Volume Name and
-L for setting the size of the Logical Volume. The Logical Volume size will be 5GB .
$ sudo lvcreate -n mypart -L 5g myvg
LVM provides a lot of features against standard disk usage. We can resize the Logical Volume or partition on the fly without unmounting or restarting the system. This operation also called
extending where we will use
-L option is used to specify how much disk space will be added .
$ sudo lvextend -L 5g myvg/mypart