Automating LVM Partition using Python-Script!!!

What is LVM??
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.
The physical volumes are combined into logical volumes, with the exception of the /boot
partition. The /boot
partition cannot be on a logical volume group because the boot loader cannot read it. If the root (/
) partition is on a logical volume, create a separate /boot
partition which is not a part of a volume group.Since a physical volume cannot span over multiple drives, to span over more than one drive, create one or more physical volumes per drive.

It is a system of managing logical volumes or filesystems, that is much more advanced and flexible than the traditional method of partitioning a disk into one or more segments and formatting that partition with a filesystem.
There are 3 concepts that LVM manages:-
~ Physical Volume
~Volume Groups
~Logical Volumes
Physical Volumes:-
Physical block devices or other disk-like devices (for example, other devices created by device-mapper, like RAID arrays) are used by LVM as the raw building material for higher levels of abstraction. Physical volumes are regular storage devices. LVM writes a header to the device to allocate it for management.
Volume Groups:-
LVM combines physical volumes into storage pools known as volume groups. Volume groups abstract the characteristics of the underlying devices and function as a unified logical device with a combined storage capacity of the component physical volumes.
Logical Volumes:-
A volume group can be sliced up into any number of logical volumes. Logical volumes are functionally equivalent to partitions on a physical disk, but with much more flexibility. Logical volumes are the primary component that users and applications will interact with.
Step1:- We can automate the partition using the python code
Here, is the python code to automate the LVM partition.




Now, I attached a external storage device of 20 GB.

Step2:- We have device empty. i.e;/dev/sdb we will use this and checking also to the external storage.

Step3:- Now, create Physical Volume for LVM by press 1.

Step4:- We will create a Volume Group from that Physical volume using option 2.

Step5:- Now, using option 3 we can see the Logical Volume that we have created.

Step6:- By using option 5 we can also Increase the size of Logical Volume to mount device.
