Linux LVM Logical Volume management partition zoning

Source: Internet
Author: User

0X00 LVM is what, what's the use

The full name of the LVM is Logical Volume Manager (Logical Volume management). is a disk partition management mechanism under Linux to facilitate the expansion and compression of partitions (logical partitions). The simplest way to understand the original disk partition management is simply to partition each individual disk and then manage each partition, so that each expansion and compression space can be cumbersome. LVM is the equivalent of rubbing all the partitions of a disk together, forming a large disk or a large partition, and then separating the small from the big one, so that the expansion and compression will be convenient.

0X01 Basic Terminology Interpretation

PV is the physical Volume physical volume---which is the real disk partition
VG is a group of Volume group volumes---which is a lot of PV
The LV is the Logical Volume logical Volume---is the partition that is separated from the VG
PE is physical Extent physical area---is the smallest storage unit in PV
LE is Logical Extent logical area---is a small storage unit in LV
0X02 test Environment

CentOS 7.x 64bit in V-box
A virtual disk with two or more volumes
Disk size is above 1GB
I am here/dev/sdb and/DEV/SDC is just added disk
The root user's ~/lvm-mount is used to mount the logical volume
Use root login (simply because every sudo is too troublesome)
0X03 Prep Partition

Use FDISK for disk partitioning
You don't use Fdisk, you can just hit me with that.
Or is it advisable to master the most basic fdisk partitioning and formatting before learning LVM
FDISK/DEV/SDB # Use Fdisk to/DEV/SDB partition
Press N to enter a new partition
Select New partition as primary partition by P-return
Press ENTER to select the default partition number
Press ENTER defaults to select Start position
Enter +100m carriage return to select the size of the new partition using 100M
Enter T carriage to set partition type
Press ENTER to select the partition you just created
Enter 8e settings The partition you just created is an LVM type
Repeat the above steps to give/Dev/sdb three separate districts
0X04 Create physical Volume PV

When you create a physical volume, you can have different sizes or partitions of different disks, as long as a 8e type of partition can be created into a physical volume, just for demonstration purposes.
# Create
Pvcreate/dev/sdb1
Pvcreate/dev/sdb2
Pvcreate/dev/ddb3
# check
Pvdisplay
# Delete (do not follow this step)
Pvremove/dev/sdb1
0x05 Prepare volume Group VG

Create a volume group that includes/DEV/SDB1/DEV/SDB2/DEV/SDB3 physical volumes
Named Volme-group1
# Create
Vgcreate VOLUME-GROUP1/DEV/SDB1/DEV/SDB2/DEV/SDB3
# check
Vgdisplay
# Delete (do not follow this step)
Vgremove Volume-group1
0X06 Create Logical Volume LV

To specify a name, size, and subordinate VG when creating a logical volume
# Create
Lvcreate-l 100m-n LV1 Volume-group1
# check
Lvdisplay
# Format formatted as EXT4 type
Mkfs.ext4/dev/volume-group1/lv1
# mount
mkdir ~/lvm-mount #设置一个挂载点
Mount/dev/volume-group1/lv1 ~/lvm-mount # Mount
# Delete
Lvremove/dev/volume-group1/lv1
0X07 Extended LVM Logical Volume

Adjusting the logical volume size is the most important and useful feature of LVM.
For example, the 100MB partition created earlier is not enough, so we need to expand the size of that partition. Although LVM is powerful, it still needs to unload the LV when it expands
# Uninstall LV
Umount ~/lvm-mount/
# Adjust Size
Lvresize-l 200M/DEV/VOLUME-GROUP1/LV1
# Check for disk errors (not required)
E2fsck-f/DEV/VOLUME-GROUP1/LV1
# Extended File System
Resize2fs/dev/volume-group1/lv1
# validation
Lvdisplay
0X08 Compressed LVM Logical Volume

For example, if you find that a partition is very large, but not used at all, then you can compress its space and use the space in a useful place.
# Similarly, uninstall first
Umount/dev/volume-group1/lv1
# Check for errors
E2fsck-f/DEV/VOLUME-GROUP1/LV1
# Update File System Information
Resize2fs/dev/volume-group1/lv1 100M
# compressed Space
Lvresize-l 100M/DEV/VOLUME-GROUP1/LV1
Here will be a warning to tell you that this operation may cause data loss, of course, is generally not a problem
0x09 Extended Volume Group

One day the server's disk is full, you bought a new 3TB hard disk plugged into the computer, then how to let this 3TB and the previous space to work together? We can also put this disk partition into the previous VG (volume group) so that the new 3TB can be used in the system by the previous expansion function.
# New Partitions First (refer to 0x03 steps)
Fdisk/dev/sdc
# then create PV (physical volume)
Pvcreate/dev/sdc1
# Add new PV to VG
Vgextend VOLUME-GROUP1/DEV/SDC1
# verify
Vgdisplay

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.