Skip to content

Logical Volume Manager (LVM) πŸ’½

Posted on:May 29, 2023 at 02:00 PM

LVM is a logical volume manager for the Linux kernel that allows you to manage disk storage. It is a device mapper target that provides logical volume management for the Linux kernel.

LVM combines multiple physical disk drives into a single β€œvirtual” drive (Volume group). This virtual drive can then be divided into one or more logical volumes. Each logical volume can be formatted with a filesystem and mounted as a separate drive.

LVM

Advantages of LVM

Disadvantages of LVM

LVM Components

How data is stored in LVM

LVM

Usage

Before creation of a Physical Volume, you need to create a partition on the disk. You can use fdisk or gdisk to create a partition. (or you can use a whole disk as a Physical Volume).

lvm-managment

Create a Physical Volume

pvcreate /dev/sda2 /dev/sdb2

After creating a Physical Volume, you can create a Volume Group.

Create a Volume Group

vgcreate vg0 /dev/sda2 /dev/sdb2

Finally, you can create a Logical Volume.To create a Logical Volume, you need to specify the size of the Logical Volume. You can specify the size in megabytes (MB), gigabytes (GB), or terabytes (TB). Also, you can specify the size as No. of Physical Extents (PEs).

Create a Logical Volume using size in MB or GB

lvcreate -L 1024MB -n lv0 vg0

Create a Logical Volume using No. of Physical Extents (PEs)

lvcreate -l 50 -n lv0 vg0

After creating a Logical Volume, you can format it with a filesystem and mount it.


Support for lvextend and lvreduce

Some filesystem support resizing.while some filesystem does not supports resizing.

The following table shows the support for resizing in some file system.

lvm-resize

To expand a Logical Volume ( lvextend )

lvextend -L +1024MB /dev/vg0/lv0

To shrink a Logical Volume( lvreduce )

lvreduce -L -1024MB /dev/vg0/lv0

πŸ” Back to Usage