Linux- LVM

Khemnath chauhan
4 min readDec 22, 2022

--

Logical Volume Manager (LVM) is a device mapper framework that provides logical volume management for the Linux kernel.The Logical Volume Manager (LVM) provides tools to create virtual block devices from physical devices. Virtual devices may be easier to manage than physical devices, and can have capabilities beyond what the physical devices provide themselves.

LVM-Layout

With LVM, you can create logical volumes that span multiple physical disks, allowing you to easily grow or shrink the size of your disk partitions as your needs change. This can be useful when you need to allocate more space to a particular filesystem, or when you need to redistribute space among multiple filesystems

A Volume Group (VG) is a collection of one or more physical devices, each called a Physical Volume (PV).

A Logical Volume (LV) is a virtual block device that can be used by the system or applications. Each block of data in an LV is stored on one or more PV in the VG, according to algorithms implemented by Device Mapper (DM) in the kernel.

Steps to Join 2 or more HardDisk to create a Volume group. Volume Group gets space for PV(Physical volume) which is harddisk.

STEP 1: Convert the HardDisk to PV (Physical volume).

To get harddisk details use command fdisk -l

$ pvcreate << physical disk >>

After creation of PV, we can display the PV details using the command — pvdisplay

STEP 2: Create Volume group.

$ vgcreate iiecvg /dev/sdc /dev/sdd

To display volume group we can use the command- vgdisplay <<volumegroupname>>

Now, the PV has been allocated:

We can also view volume group:

The act option stands for "active" and is used to show only active volume groups. An active volume group is a volume group that is currently in use by the system.

STEP 3: Create LV — as we have already created the VG.

$ lvcreate — size 50G — name mylv1 <<VG-Name>>

create lv

To display the LV details.

$lvdisplay <<LV_Name>>

Technically, every partition is like a device and hence the path for the partition is under — /dev/iieccvg/mylv1

To view all the Logical Volume.

STEP 4: Finally, formatting the partition.

$ mkfs.ext4 <<Partition Path>>

Format

To Use the Partition:

  • Create a Directory
  • Mount the partition on a Directory.
  • ** When using LVM you don’t need to go offline.

Getting additional space on LV from VolumeGroup(VG).

$ lvextend --size +<<SizeValue>> <<Lvname>>

To view the new size lvdisplay the partition.

However, this will still not reflect still when you use → df -hT
As df
will only show part of the disk partition that is formatted.

So, to reflect the new added space, we need to format the new space, however if we format with mkfs we will lost all data. There is a great command we can use in such scenarios — resize2fs. This command will only format the new part and will not touch the old part.

$ resize2fs <<partition>>

As long as VG have space we can extend LV, When the space runs out, it will not allow to add addtional space.

Similarly, if the VG space needs to be extended and need to add additional PV, we can use vgextend command.

$ vgextend <<Vgname>> <<Disk>>
$ vgextend myvg /dev/sde

--

--

Khemnath chauhan
Khemnath chauhan

No responses yet