Linux Logical Volume Manager (LVM)

Source: Internet
Author: User

In real life, we often encounter this situation, we have bought a hard disk partition into a lot of disk, so that we can classify files, but there are also some problems, that is, if the partition is full of what to do? Or we want to subdivide a disk, all of which can be solved with Linux under a powerful management tool, that is, LVM.


So what is LVM? LVM is: Logical Volum Manager (Logical Volume manager)

So how does an LVM really come true?


LVM consists of three parts: PV (physical volume)

VG (logical Volume Group)

LV (logical volume)


Simply put, it is a virtual disk of multiple physical disks or a physical disk virtual into multiple disks

"Simple understanding of LVM" Here the PV refers to our physical storage device, and we have physical storage device is not what we usually see, but in the internal chunking, we store data when it will be large data into a small piece of physical storage device each block. And our LVM is a manager that can put these PV together, so that we can break the boundaries of the block device storage, realize the integration of multiple physical storage devices into one device.


So the storage space boundary is divided into two parts : physical boundary, logical boundary

"The relationship between physical boundaries and logical boundaries" now that we have physical boundaries and logical boundaries, what do we do about expansion and reduction of storage space?

It is conceivable from the above narrative that logical boundaries are virtual based on physical boundaries, so no matter how big the logical boundary is, it cannot be larger than the physical boundary.

So the "expansion of storage Space": Extend the physical boundary and then extend the logical boundary first

"Storage space Reduction": Reduce logical boundaries and reduce physical boundaries first

Note: Scaling must not be less than the size of all data spaces that have been stored

If the reduction is less than the size of the existing storage space data, then the data should be moved out and then reduced to avoid data loss.


Now that you know the composition of the logical volume, then start creating the logical volume.


"Creating a Logical Volume"

LVM creates objects that can be block devices or raid

Create a step: first create the PV and then create the VG last create the LV

"Commands to use when creating PV": pvcreate (Create), PVs (view), Pvdisplay (view), Pvremove (remove), Pvmove (mobile), Pvscan (scan)

"Commands to use when creating VG": vgcreate (Create), VGS (view), Vgdisplay (view), Vgremove (remove), vgreduce (delete), Vgscan (scan), vgextend (add)

"Commands to use when creating a LV": lvcreate (Create), LVS (view), Lvdisplay (view), Lvremove (remove), lvreduce (delete), Lvscan (scan), lvextend (add)

Here's a list of things for everyone:

Create two partitions on the SDB hard drive, making the two partitions a logical volume

1. Create the partition and set the two partition IDs to 8e (Linux LVM)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/3F/A7/wKioL1PL0tvzBl2IAAK5T0ybets302.jpg "title=" Create the partition. jpg "alt=" wkiol1pl0tvzbl2iaak5t0ybets302.jpg "/>


2. Create PV

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3F/A7/wKiom1PL0m6zocfgAADTYlxMzMs462.jpg "title=" Create Pv.jpg "alt=" Wkiom1pl0m6zocfgaadtylxmzms462.jpg "/>


Once created, let's look at

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3F/A7/wKioL1PL09aiH_lCAACdkHu2p24631.jpg "title=" Pvs.jpg "alt=" Wkiol1pl09aih_lcaacdkhu2p24631.jpg "/>


3. Create VG

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3F/A7/wKiom1PL01eyHNS-AAGrY5gtKa4038.jpg "title=" Create Vg.jpg "alt=" Wkiom1pl01eyhns-aagry5gtka4038.jpg "/>


This is to create a volume group named "Myvg" and add the SDB1 and SDB2 under/sev to the secondary volume group. In view of the results of the command execution, we can see that there are two PV in the MYVG volume group.

4. Create a logical volume

The command to create a logical volume is: lvcreate

"lvcreate command uses format" lvcreate option logical Volume name Volume group name

The options are:-n followed by the logical volume name

-L heel Size (specifies logical volume space size)

such as: Lvcreate-l 2g-n mylv myvg (meaning: Create a logical volume named Mylv with a space size of 2G and a volume group of MYVG)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/3F/A7/wKioL1PL1y_jJeQkAABsgYj3558394.jpg "title=" Create Lv.jpg "alt=" Wkiol1pl1y_jjeqkaabsgyj3558394.jpg "/>


What if we want to access the logical volume after we create it?

There are two access paths for each logical Volume:/dev/volume Group name/Logical volume name

/dev/mapper/Volume group name-Logical volume name

Note: Both paths are symbolic links, pointing to a file of/dev/dm-# (#表示数字)



If you want to use this logical volume, do not forget to format the secondary volume and then mount it (although it is a logical volume, but the usage and partition are the same)


Format: Mke2fs-t ext4/dev/myvg/mylv

Mount: Mount/dev/myvg/mylv Heel mount point



"Expansion and reduction of logical volumes"

Extension: 1, first determine the target size of the extension, and ensure that there is sufficient space available in the corresponding volume group.

2. Extend physical boundary such as: lvextend-l 4g/dev/myvg/mylv (meaning expansion to 4G)

3, extended logical boundary such as: Resize2fs/dev/myvg/mylv 4G (meaning to expand to 4G)

Reduction: 1, first determine the reduced target size, and ensure that the corresponding target logical volume size has enough free space available, can accommodate all the original data.

2, first unmount the file system, and to perform mandatory detection: E2fsck-f heel device

3, reduce the logical boundary such as: Resize2fs/dev/myvg/mylv 2G (meaning to reduce to 2G)

4, reduce physical boundaries such as: lvreduce-l 3g/dev/myvg/mylv (meaning to reduce to 3G)

Note: Reduction is dangerous to use with caution, a little caution will result in data loss.



Big data for some companies needs to be backed up frequently, but there are some more troublesome problems with backup.

For example: When the amount of data that needs to be backed up is relatively large, the time to back up the data becomes quite long, but what happens when there is data to be written? Are we the data that didn't change before the backup or the new data?

How to solve this problem?

And then there's the snapshot volume.

"Snapshot Volume"

role: primarily used for data backup

principle: Take a picture of the data to be backed up, record the current data, and then form a map within the snapshot volume, mapped to the data on the hard disk, once the data on the hard disk changes the snapshot volume will replicate the changes before the data into the snapshot volume, no changes in the data is not copied to the snapshot volume, When a backup operation occurs, data that is not changed is copied to the hard disk, and the changed data is copied to the snapshot volume. (So the size of the snapshot volume is not necessarily as large as the original storage space)

"Snapshot Volume Creation"

The first snapshot volume is also a logical volume, so the steps to create are basically the same as the logical volume creation steps.

Just add the option "-S" when creating a logical volume in the last step

Example: Lvcreate-l 512m-n mylv-snap-p r-s/dev/myvg/mylv (meaning to create a read-only snapshot volume with a size of 512M named Mylv-snap,-P R means read-only)

Note: The snapshot volume is on a logical volume and must be in the same volume group as the destination logical volume without indicating the volume group.



Linux Logical Volume Manager (LVM)

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.