Size of dynamically expanding LVM logical volumes in CentOS

Source: Internet
Author: User

LVM Concepts:
--------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------
It is a mechanism for managing disk partitions in a Linux environment, and LVM is a logical layer built on hard disks and partitions to improve the flexibility of disk partition management. The LVM system administrator makes it easy to manage disk partitions, such as connecting several disk partitions to a single block of volume Group (volume group), forming a storage pool. Administrators can create logical volume groups (logical volumes) at will on the volume group, and further create file systems on logical volume groups. LVM makes it easy for administrators to resize storage volume groups and to name, manage, and assign disk storage as a group. When a new disk is added to the system, the LVM administrator does not have to move the disk's files to the new disk to take full advantage of the new storage space, but instead directly extend the file system across the disk. Its structure is as follows:

Several conceptual explanations
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------
PV (physical volume): Physical volumes are at the bottom of the logical volume management system and can be partitions on the entire physical hard disk or on the actual physical hard disk. It simply outlines a specific area in the physical partition that is used to record LVM-related management parameters.
VG (Volume Group): A volume group is built on a physical volume, and a volume group must include at least one physical volume, which can be dynamically added to the volume group after the volume group is established, and can have multiple volume groups in a logical volume management system engineering.
LV (logical volume): Logical volumes based on volume groups, unallocated space in a volume group can be used to establish new logical volumes that can be dynamically scaled and scaled down after the logical volume is established.
PE (physical extent): The physical region is the smallest storage unit available for allocation in a physical volume, the physical region size is specified when the volume group is established, and once determined that it cannot be changed, the physical region size of all physical volumes of the same volume group must be the same, the new PV is added to the VG, The size of the PE is automatically changed to the PE size defined in the VG.
LE (logical extent): The logical region is the smallest storage unit that can be allocated in a logical volume, and the size of the logical region depends on the size of the physical region in the volume group where the logical volume resides. Due to kernel limitations, a logical volume (logic Volume) can contain up to 65,536 PE (physical Extent), so the size of one PE determines the maximum capacity of a logical volume, and a 4 MB (default) PE determines the maximum capacity of a single logical volume to be up to three GB , if you want to use a logical volume larger than 256G, you need to specify a larger PE when creating the volume group. In red Hat Enterprise Linux as 4, the PE size range is 8 KB to 16GB and must always be a multiple of 2.

Next, cite a few examples to illustrate:
--------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------
1. Prepare physical partitions (physical partions)
First, we need to select the physical memory for LVM. These are typically standard partitions, but can also be Linux software RAID volumes that have been created. Here I use the Fdisk command to divide the SDB, SDC two disks into two extents sdb1, SDC1, and specify the partition as a 8e type (Linux LVM) with the t instruction of Fdisk, such as:

2. Creating a physical volume PV (physical Volumes)
[[Email protected] Oracle] #pvcreate/DEV/SDB1
Physical volume "/DEV/SDB1" successfully created
[Email protected] oracle]# PVCREATE/DEV/SDC1
Physical volume "/DEV/SDC1" successfully created

3. Create Volume Group VG (Volume Groups), named Vg_test
[[email protected] ~] #vgcreate VG_TEST/DEV/SDB1
Volume Group "Vg_test" successfully created
Use Volume Group View command vgdisplay Display volume group condition:
[[email protected] oracle]# Vgdisplay
---Volume group---
VG Name vg_test
System ID
Format lvm2
Metadata areas 1
Metadata Se Quence No 6
VG Access read/write
VG Status resizable
Max LV 0
Cur LV 1
Open LV 1
MAX PV 0
Cur PV 1
Act PV 1
VG size 19.99 GB
pe Size 4.00 MB
Total PE 5118
Alloc pe/size 2560/10.00 GB
Free Pe/size 2558/9.99 GB
VG UUID YEYTOR-JPCK-P7MV-FFVO-BGEI-OOEF-IG3HLC

4. Create a logical Volume LV (Logical Volumes), named Test_lv
Create Logical Volume command to set logical partition size for lvcreate,-l parameter to fixed PE number, or you can specify logical partition size directly using the-l parameter , the-n parameter specifies the logical partition name.
[[email protected] oracle]# lvcreate-l 2000-n lv_test vg_test
Logical Volume "Lv_test" created
You can also use the-l parameter Number
[[email protected] oracle]# lvcreate-l 10g-n lv_test vg_test
Rounding up size to full physical extent 19.9 9 GB
Logical Volume "lv_test" created
Use the Lvdisplay command to view the logical volume condition:
[[email protected] Oracle] #lvdisplay
- --Logical Volume---
LV name/dev/vg_test/lv_test
VG Name vg_test
LV UUID kguomy-w1qg-7taq-di5j-z2ko-a8td-mxa FBC
LV Write Access read/write
LV Status available
# Open 0
LV Size 19.99 GB
Current LE 5118
Segme NTS 1
Allocation inherit
Read ahead sectors Auto
-currently set to
Block device 253:2

5. Create a file system and mount
To create the Ext3 file system on a logical Volume:
[[Email protected] Oracle] #mkfs-T Ext3/dev/vg_test/lv_test
[[Email protected] Oracle] #mount/dev/vg_test/lv_test/opt/oracle/
[Email protected] oracle]# df-h
Filesystem Size used Avail use% mounted on
/dev/mapper/volgroup00-logvol00
16G 4.7G 11G 32%/
/DEV/SDA1 99M 27M 67M 29%/boot
Tmpfs 872M 0 872M 0%/dev/shm
/dev/mapper/vg_test-lv_test
9.9G 151M 9.2G 2%/opt/oracle

The biggest benefit of LVM is the ability to dynamically resize partitions without restarting the machine, let's experience it!
Continuation of the above example, now assume that the logical volume/dev/vg_test/lv_test space, need to increase its size, we have two kinds of situations discussed:
---------------------------------------------------------------------------------------------------------
1. There is space left in the volume group
The Vgdisplay command allows you to check the current volume group space usage:


[Email protected] oracle]# Vgdisplay
---Volume Group---
VG Name Vg_test
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access Read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
ACT PV 1
VG Size 19.99 GB
PE Size 4.00 MB
Total PE 5118
Alloc pe/size 2560/10.00 GB
Free Pe/size 2558/9.99 GB
VG UUID YEYTOR-JPCK-P7MV-FFVO-BGEI-OOEF-IG3HLC
Determines the remaining space of the current volume group is 9.99GB, the remaining PE quantity is 2,558. Here all the remaining space is added to the logical volume/dev/vg_test/lv_test.
[Email protected] oracle]# lvextend-l +2558/dev/vg_test/lv_test
Extending logical Volume Lv_test to 19.99 GB
Logical Volume Lv_test successfully resized
You can also specify the size directly by-l to increase/decrease the space by +/-.
After modifying the logical volume size, modify the file system size by RESIZE2FS.
[[Email protected] Oracle] #resize2fs/dev/vg_test/lv_test
RESIZE2FS 1.39 (29-may-2006)
Filesystem at/dev/vg_test/lv_test is mounted on/opt/oracle; On-line resizing required
Performing an on-line resize of/dev/vg_test/lv_test to 5240832 (4k) blocks.
The filesystem on/dev/vg_test/lv_test is now 5240832 blocks long.
To see the file system size again:
[Email protected] oracle]# df-h
Filesystem Size used Avail use% mounted on
/dev/mapper/volgroup00-logvol00
16G 4.7G 11G 32%/
/DEV/SDA1 99M 27M 67M 29%/boot
Tmpfs 872M 0 872M 0%/dev/shm
/dev/mapper/vg_test-lv_test
20G 156M 19G 1%/opt/oracle


2. Insufficient space in volume group
When there is not enough space in the volume group to extend the size of the logical volume, the capacity of the volume group needs to be increased, and the only way to increase the volume group capacity is to add a new physical volume to the volume group.
You first need to partition the newly added disks, create physical volumes, and so on. ), the next step is to use the Vgextend command to add a new physical volume to the volume group, where we use/DEV/SDC1.
[[Email protected] Oracle] #vgextend VG_TEST/DEV/SDC1
Volume Group "Vg_test" successfully extended
[Email protected] oracle]# Vgdisplay
---Volume Group---
VG Name Vg_test
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 8
VG Access Read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
ACT PV 2
VG Size 59.98 GB
PE Size 4.00 MB
Total PE 15356
Alloc pe/size 5118/19.99 GB
Free Pe/size 10238/39.99 GB
VG UUID YEYTOR-JPCK-P7MV-FFVO-BGEI-OOEF-IG3HLC


After the volume group is expanded, the capacity of the logical volume can be completed in the first case, and the dynamic adjustment of the partition will be realized.

Size of dynamically expanding LVM logical volumes in CentOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.