LVM2 Logical volume creation and expansion

Source: Internet
Author: User

I. Background Introduction

LVM2 logical volume due to support the dynamic expansion or contraction of space, in small and medium-sized enterprises have a certain use of the scene in the CentOS5, 6 system often met, from CentOS7 after the default file system from Ext4 to Btrfs, and Btrfs also support the dynamic expansion and contraction of space, So it's unwise to use LVM again in a CentOS7 system.

Ii. Introduction to the principle of LVM

Before you introduce LVM, you first need to explain a few nouns:

Pv--physical volume, a disk volume consisting of disks on a physical level

Vg--volume Group, a volume group abstracted from multiple PV in a lower logical layer

Pe--physical EXTEND,VG will provide the capacity of PV again in the form of "block", the size of each "block"

Lv--logical volume, consisting of multiple LV "blocks" that make up the device files that are available for mount use

From the above figure can be seen that VG is one or more PV abstraction of a logical layer, the logic layer provided by the block size called PE, a number of PE is the LV is used to mount the device files. The expansion or contraction of space is the process of increasing or decreasing PE. LVM functionality is actually implemented through the DM module in the kernel (device mapper), which organizes one or more of the underlying block devices into a module of a logical device that is dm-under the/dev/directory #形式展现

third, create LVM2 logical volumes

1. Add a new disk, or create a few new partitions on the remaining space of the original disk (as long as the block device can be used to create LVM2), note the partition ID number if 8e

2. As you can see from the partition type, 8e is the ID number for the LVM

3. Use the PVCREATE/DEV/SDB1/DEV/SDB2/DEV/SDB3 command to create a new 3 PV, you can use the PVs view after completion

4. Use the command vgcreate [-S #[kkmmgg]] myvg/dev/sdb1/dev/sdb2/dev/sdb3 to create VG, you can use-s to set the size of the PE block, by default, 4M,MYVG is the custom VG name

5. Using the command lvcreate-l 15g-n mylv MYVG to create the LV, here is the need to note that if the LV needs to be deleted later the path of LV, that is, using the LVREMOVE/DEV/MYVG/MYLV command to complete

The creation of a good LV can be found under the/dev/mapper/through Vg_name-lv_name or under/dev/Vg_name/lv_name, both of which point to/dev/dm-#的链接

6. LV will be created at this time, using the MKE2FS command to format the LV can be mounted using the

iii. expansion of LVM2

From the previous article that the size of LV is subject to PE, VG, PV, so when to the LV expansion of the recommended steps: Expansion pv--expansion vg--expansion lv--enlarge file system size

1. Then create a partition as PV

2. Add the newly created partition to the MYVG VG, and use VGS to see that the PV number changes from 3 to 4

3. In the lvresize-l +4g/dev/myvg/mylv command to expand the LV size, here note-L +4G said that the original basis and then add 4G space, can also be written as Lvresize-l 19g/dev/myvg/ MYLV represents an increase in space size to 19G

4. While the LV space is expanded, it will be found that the size of the mounted device file space has not changed

Uninstall the original mount point, use the RESIZE2FS/DEV/MYVG/MYLV command to the filesystem expansion, and then mount the see has become 19G

Supplementary Notes

When the LV device (/DEV/MYVG/MYLV) is mounted to the/LVM directory, the prompt cannot be extended online when the file system is extended directly

Attempt to extend file system again after uninstall prompt cannot find a valid super block

Try again after reboot, prompting to check and repair the file system first

Only when the file system has been checked and expanded again can it be successful, and the reason why it is not clear

This article permanently updates the link address :

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: 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.