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.
Hi guys I’m back with another blog here we are going to create an LVM not only creating even going to merge two devices, gone an increase, decrease the size of storage. Lets dev friends
How to Resize LVM Partition Inside an Extended Partition
Creating Logical volume is not so difficult only thing needs to follow the below steps
- Create a new partition on the hard disk.
- Add the partition you just created as a physical volume.
- Add the new physical volume to the volume group.
- Assign space from the volume group to the logical volume.
- 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.
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
Creating an LVM
Before creating LVM we can see new devices not mounted.
>> df -Th
Creating a PV
>> pvcreate <disk_name>
>> pvdisplay
Creating Volume Group with name LVMgroup
>> vgcreate <Group_name> <Disk_1> <Disk_2>
>> vgdiplay <Group_name>
Creating Logical Volume
>> lvcreate --size <give_size>G --name <name_of_LV> <NameOf_VG>
>> lvdisplay <LV_name>
Do format a storage
>> resize2fs /dev/<group_name>/<LV_name>>> mount /dev/<group_name>/<LV_name> <folder_path_path_toMount>>> df -Th
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>
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>