What is LVM?
Logical Volume Manager (or.. LVM) is a Device Mapper that acts as a Logical Volume manager for a Linux system. Most modern Linux distros are LVM-ready to the point that they are able to have their root file-systems on a LV.
What is a Logical Volume?
Allocating storage divisions within a single or multiple storage devices. Ex: C: drive ,D: drive and E: drive
Why use LVM?
🔹LVM can be used to create, deleted and resized logical volumes ,online, without any restarts.
🔹Logical volumes can also be resized dynamically
🔹LVM allows the creation of instant logical volume snapshots while the operating system is running and supports advanced encryption features.
Ways of Managing LVM:
There are 3 concepts that LVM manages:
→1️⃣ Physical Volume: A physical volume is a collection of disk partitions used to store all server data.
→2️⃣ Volume Groups: is a collection of physical volumes of varying sizes and types.
→3️⃣ Logical Volumes: are groups of information located on physical volumes.
🔹 Automating LVM Partition using Python-Script
I’ve Imported OS , using os.system() we can run any system/os commands .
Making this procedure much easier than any other way
→ Inorder to use a disks in VG , we have to label them as LVM physical volumes with the
pvcreate <disk_name1> <disk_name2> <disk_nameN>
→ For creating a volume group that consists of the LVM physical volumes you have created. to creates the volume group we use cmd :
vgcreate new_vol_group <disk_name1> <disk_name2> <disk_nameN>
→ For creating the logical volume from the volume group you have created. The following command creates the logical volume
new_logical_volumefrom the volume group
lvcreate --size <size> --name <new_logical_volume> <new_vol_group>
→ For creating a file system on the logical volume. To create an ext4 file-system on the logical volume we use:
→For mounting the logical volume to the folder /test
mount /dev/new_vol_group/new_logical_volume /test
→For increasing the size of the lvm by size of our choice.
lvextend --size <size> /dev/new_vol_group/new_logical_volume
→ Format the extended part using the below command.
These have been used to create a CLI-Menu for LVM :
Testing whether the LV was created , mounted and partitioned:
Thank you for the time~!