What is LVM Partition?
LVM, or Logical Volume Manager, is a feature in the Linux operating system that allows for the management of disk storage space in a more flexible and dynamic way. LVM partitions, also known as logical volumes, are created within volume groups, which are made up of one or more physical storage devices (such as hard drives or partitions).
With LVM, you can create, resize, and delete logical volumes without having to worry about the underlying physical storage devices. This makes it easier to manage your storage space, as you can allocate and reallocate space as needed without having to worry about the physical layout of your storage devices.
In CentOS, LVM can be used to create and manage logical volumes, which can be used to create file systems, swap space, or other storage needs. The LVM partitions are created and managed using the LVM tools such as lvmdiskscan, lvdisplay, pvdisplay, vgextend, lvextend and resize2fs.
How to Extend LVM Partition on CentOS
To extend an LVM partition on CentOS, you will need to follow these steps:
Check the current LVM configuration by running the command:
Use the command:
lvdisplay
to view the current logical volume you want to extend. Make a note of the volume group and logical volume names.Use the command:
pvdisplay
to view the physical volume(s) you want to add to the volume group. Make a note of the physical volume name(s).Use the command:
vgextend
to add the physical volume(s) to the volume group. The syntax is as follows:vgextend [volume group name] [physical volume name(s)]
Use the command:
lvextend
to increase the size of the logical volume. The syntax is as follows:lvextend -L+[size]G /dev/[volume group name]/[logical volume name]
Use the command:
resize2fs /dev/[volume group name]/[logical volume name]
to resize the file system to match the size of the new logical volume.Here is an example:
# lvmdiskscan
/dev/sda1 [ 50.00 MiB]
/dev/sdb1 [ 50.00 MiB]
/dev/sdc1 [ 50.00 MiB]
2 disks
0 partitions
0 LVM physical volume whole disks
2 LVM physical volumes
# lvdisplay
--- Logical volume ---
LV Path /dev/my_volgroup/my_logicalvol
LV Name my_logicalvol
VG Name my_volgroup
LV UUID mF7jIc-TfLc-9XS8-f7Vx-pwF1-Jjn4-Wn7V3v
LV Write Access read/write
LV Creation host, time localhost, 2020-09-11 13:35:07 +0530
LV Status available
# open 1
LV Size 20.00 GiB
Current LE 5120
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
# pvdisplay
--- Physical volume ---
PV Name /dev/sdd1
VG Name my_volgroup
PV Size 50.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12800
Free PE 12800
Allocated PE 0
PV UUID dY9XnK-fLxv-i1pL-d5mB-jK5Q-o8Zf-Y1X9Kj
# vgextend my_volgroup /dev/sdd1
Volume group "my_volgroup" successfully extended
# lvextend -L+20G /dev/my_volgroup/my_logicalvol
Extending logical volume my_logicalvol to 40.00