What is LVM, LVM Architecture? How to create PVs,VGs, LVs in Linux?
What is LVM?
LVM stands for Logical Volume Manager, a powerful tool that transforms the way we handle storage in Linux and Unix-like systems. LVM allows you to manage disk drives and storage devices in a more flexible and dynamic way. Instead of dealing with traditional partitions, LVM introduces the concept of logical volumes.
Why we need LVM?
Normally we can’t resize partitions in Linux but By using LVM, you can create, resize, move, and delete logical volumes on the fly, without necessarily needing to repartition your hard drive.
The real magic of LVM lies in its ability to resize logical volumes and volume groups on-the-fly. Need more space for that growing database? LVM makes it a breeze, without interrupting operations. We can think of it as a thin layer of software on top of hard disks which creates an abstraction of continuity and ease of managing hard drives.
Logical Volume Manager stands as a testament to adaptability and efficiency. By embracing LVM, administrators and users alike gain unprecedented control over their storage infrastructure, ushering in an era where the limitations of traditional partitions are a thing of the past.
LVM Architecture:
The basic flow in LV Creation is:
Hard Disk > PV > VG > LVs
PV(Physical Volume)
These can be represented as actual hard drives, RAW storage, partitions, or RAID arrays. Visually depict a few of these units with labels like “sda,” “sdb,” etc.
VG(Volume Group)
A collection of one or more physical volumes. It acts as a pool of storage. We can add as many Physical volumes in Volume group as needed.
LV(Logical Volume)
It is a virtual partition created within a Volume Group (VG), They act as virtual partitions. LVs can be sized and resized dynamically, providing flexibility in managing Storage. Logical volumes has File system, we can mount them on any directory
How To Create PV, VG, LV in Linux?
Useful Linux commands which helps you during LVM managment.
View the total no of hard disks, partitions, storage size and available size
#lsblk
View the total number of Physical Volumes:
#pvs
OR
#pvdisplay
View Volume groups
#vgs
OR
#lvdisplay
View Logical volumes
#lvs
OR
#lvdisplay
PV Creation:
For example after running “lsblk” command we find out that we have a partition named “/dev/vda”. Now the command for creating a PV from disk “/dev/vda” is:
#pvcreate /dev/vda
VG Creation:
For example we have 2 physical volumes “/dev/vda” and “/dev/vdb”, now to create a volume group from these physical volumes we can use this command:
#vgcreate VolumeGroupName /dev/vda/ /dev/vdb
“VolumeGroupName” is the name of volume group.
LV Creation:
For example we have a volume group named “NewVolumeGroup” and we want to create a Logical volume(LV) named “NewLogicalVolume”, we can create a logical volume by using the following command:
#lcreate -n NewLogicalVolume -L 20G NewVolumeGroup
“-n” is used to declare name of Logical Volume
“-L” used to declare the size of LV
Can we extend the Volume Group? How to extend VG(Volume Group)?
Yes!, We can extend our volume group by adding a new Disk(Or we can say a new physical volume).For example we have a VG of 20G and now we want to extend it to 30G we can add a new disk of 10G in our volume group with this command:
#vgextend NewVolumeGroup /dev/vdc
How to extend LV(Logical Volume)?
#lvextend -L +10G /dev/NewVolumeGroup/NewLogicalVolume
“-L +10G” is the size we want to add in existing Logical volume.
Conclusion:
In the realm of Linux and Unix-like systems, Logical Volume Manager (LVM) emerges as a transformative force, reshaping how we interact with storage. LVM introduces the concept of logical volumes, providing a dynamic and flexible approach to managing disk drives. The need for LVM becomes evident when faced with the limitations of traditional partitions — LVM empowers us to create, resize, move, and delete logical volumes seamlessly.
In embracing LVM, administrators and users gain unprecedented control over their storage environment, ushering in an era where adaptability and efficiency redefine the landscape. LVM stands not just as a tool but as a testament to the evolving nature of storage management, where the constraints of traditional partitions are rendered obsolete.