LVM(Logical Volume Manager)

In Linux, Logical Volume Manager is a device mapper framework that provides logical volume management for the Linux kernel. Most modern Linux distributions are LVM-aware to the point of being able to have their root file systems on a logical volume. In this, we can extend two storage devices, increase, decrease sizes this is the main benefit.

How to Resize LVM Partition Inside an Extended Partition

Creating Logical volume is not so difficult only thing needs to follow the below steps

  1. Create a new partition on the hard disk.
  2. Add the partition you just created as a physical volume.
  3. Add the new physical volume to the volume group.
  4. Assign space from the volume group to the logical volume.
  5. Resize the filesystem.

What is Partition?

Creating disk partitions enables you to split your hard drive into multiple sections that act independently. In Linux, users must structure storage devices (USB and hard drives) before using them. Partitioning is also useful when you are installing multiple operating systems on a single machine.

What is Logical Volume?

LVM is a tool for logical volume management which includes allocating disks, striping, mirroring, and resizing logical volumes. With LVM, a hard drive or set of hard drives is allocated to one or more physical volumes. LVM physical volumes can be placed on other block devices which might span two or more disks. Without a properly initialized volume group, you cannot create Logical Volume.

What is Volume Group?

A volume group ( VG ) is the central unit of the Logical Volume Manager (LVM) architecture. It is what we create when we combine multiple physical volumes to create a single storage structure, equal to the storage capacity of the combined physical devices. Without physical Volume, we can’t create a Volume Group.

What is Physical Volume?

A physical volume is any physical storage device, such as a Hard Disk Drive ( HDD ), Solid State Drive ( SSD ), or partition, that has been initialized as a physical volume with LVM. Without properly initialized physical volumes, you cannot create Volume Groups or logical volumes without group volume we can’t create Logical Volume.

Internal working

Let’s dev into practical

Shut down your VM and increase the disk size

First, shut down your VM and increase the disk size. Here, I have increased the disk or added two new disks /dev/sde and /dev/sdh of size 30 GB. Then start your VM and go to the console.

We can see disks from below

>> fdisk -l
Shows fdisks

Creating an LVM

Before creating LVM we can see new devices not mounted.

>> df -Th
shows mounted devices

Creating a PV

>> pvcreate <disk_name>
>> pvdisplay
Create PV (Physical Volume)

Creating Volume Group with name LVMgroup

>> vgcreate <Group_name> <Disk_1> <Disk_2>
>> vgdiplay <Group_name>
Create LV

Creating Logical Volume

>> lvcreate --size <give_size>G --name <name_of_LV> <NameOf_VG>
>> lvdisplay <LV_name>
Create LV

Do format a storage

>> resize2fs /dev/<group_name>/<LV_name>>> mount /dev/<group_name>/<LV_name> <folder_path_path_toMount>>> df -Th
Format storage

From the above image, we can see that our logical volume is mounted to one of the folder

Increase Size of Logical Volume

>> lvextend --size +<Size_to_increase>G /dev/<group_name>/<LV_name>
>> resize2fs /dev/<group_name>/<LV_name>
Increase LVM

Decrease A Logical Volume Size

Before decreasing make sure your storage is unmounted

>> umount <mounted_path>

Remove from metadata

>> e2fsck  -f /dev/<group_name>/<LV_name>

Reformated only reduced data

>> resize2fs /dev/<group_name>/<LV_name> <sizeToFormat>G

Now we are safe to reduce storage, reducing Logical Volume

>> lvreduce -L <sizeToReduce>G /dev/<group_name>/<LV_name>
Decreasing Logical Volume

Thanks for Reading !!

Keep Learning !! Keep Sharing !!

You can contact me on😅:

LinkedIn emailme

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vinodha kumara

DevSecOps, MLOps, Cloud Computing, DE, ML, DL, Programmer, Blogger, Volunteer