LVM management and usage

Source: Internet
Author: User

LVM: logical volume manager, called the logical volume manager. Now we use lvm2, which is provided by the DM module in Linux, A tool that organizes one or more underlying Block devices into one logical device. LVM supports only one device at the underlying layer. You can map one or more underlying Block devices into one logical device. Similar to the extended partition, you also need to divide the partition into logical partitions before further formatting and then attaching it for use, LVM simply organizes the space capacity boundaries of underlying Block devices into a single device. On this basis, it can further divide logical partitions of different sizes, when these logical partitions are insufficient, online scaling is also supported.

Basic concepts involved in LVM

PV: Each physical device at the underlying layer is called PV, also known as a physical volume.

VG: when each physical disk is combined by LVM, the larger disk space is called VG, which is called a volume group. The volume group specifies the size of the data block.

PE: when creating VG, you must specify the size of each data block. This block is usually much larger than the disk block commonly used in our file system, generally, it is an integer multiple of 2 ^ N. Each physical device is divided into blocks. These blocks are called PES and are called physical disk areas.

Le: the size of the data block specified by the volume group, that is, a storage unit. At the logical volume level, it is no longer called PE, but called Le: Logical extend. They are of the same size, it is a basic storage unit defined by LVM. It is only from different perspectives. It is called pe from the perspective of physical volume and Le from the perspective of logical volume.

Snapshot volume: LVM allows you to create snapshots for logical volumes. You can create a logical volume in an image format to Backup Redundancy to some extent.

How to Use LVM to create PV, VG, LV, and snapshot volumes and precautions.

Create a PV. Suppose there are two disk partitions:/dev/sda3 (7g) And/dev/sda5 (3G, and adjust its partition type to 8E, which we simulate in the virtual machine. In actual use, it should be composed of different disk devices.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/3F/81/wKiom1PKCqbCdBIUAAEs_WeYU9Q609.jpg "Title =" 1.png" alt = "wkiom1pkcqbcdbiuaaes_weyu9q609.jpg"/>

Create PV:

# Pvcreate/dev/sda3/dev/sda5

# PVS; view PV creation results


650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/3F/81/wKioL1PKC8yw7gCFAACx1lNsnSY560.jpg "Title =" 2.png" alt = "wkiol1pkc8yw7gcfaacx1lnsnsy560.jpg"/>

Create VG:

# Vgcreate/dev/myvg/dev/sda3/dev/sda5; the PE size can be specified here.

# Vgs; view the VG creation result

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/3F/81/wKioL1PKDC7BuEsHAACJPoOsWS4406.jpg "Title =" 3.png" alt = "wkiol1pkdc7bueshaacjpoosws4406.jpg"/> 650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/3F/81/wKiom1PKCzTDrxQwAAF3Jc_44tY339.jpg "Title =" 4.png" alt = "wkiom1pkcztdrxqwaaf3jc_44ty339.jpg"/>

Suppose that the disk space of VG is large, the usage is not enough, and there is a lot of space left, and we want to cancel a disk. The procedure is as follows:

First, confirm the space used by the created VG. This value is composed of multiple LV spaces. Of course, the entire VG space can be used only for one lV, if the available space of the entire VG is greater than that of a disk to be removed, the disk can be removed from the VG, otherwise, data cannot be completely copied from the corresponding disk to another disk in the volume group. Move the data in the disk to another physical disk (PV). Assume that/dev/sda5 is removed.

# Pvmove/dev/sda5;

# Vgreduce myvg/dev/sda5; or use pvremove/dev/sda5

In this way, the physical disk can be removed.

 

Create LV (assuming 5 Gb)

# Lvcreate-N/dev/myvg/mylv-L 5g

# LVS: view the LV creation result

After that, the LV can be formatted and mounted for use. For example, you can format mylv into the ext4 format and mount it to the directory.

# Mke2fs-T ext4/dev/myvg/mylv

# Mount/dev/myvg/mylv/users

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/3F/81/wKiom1PKC5ORwdf0AAFJGJ7HRMA493.jpg "Title =" 5.png" alt = "wkiom1pkc5orwdf0aafjgj7hrma493.jpg"/>

Expand the LV space. If it is expanded to 7 GB, LVM supports online expansion.

# Lvextend/dev/myvg/mylv-L 7g; physical boundaries are extended here

# Resize2fs/dev/myvg/mylv; the size of the extended logical boundary is the same as that of the physical boundary

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/3F/81/wKioL1PKDS2gfoTaAAFJPgAY-HQ984.jpg "Title =" 9.png" alt = "wKioL1PKDS2gfoTaAAFJPgAY-HQ984.jpg"/> generally, the logical boundary of LV is extended after its physical boundary, logical editing automatically scales up the same size as its physical boundaries.

To reduce the space of the LV, unmount it first. Note that when the LV is reduced, you must first cancel the mounting, and then use the e2fsck command to forcibly check the disk, and then reduce it, in addition, the order of reduction requires that the logical boundary be reduced first, and then the physical boundary be reduced. The sequence cannot be wrong. In addition, data may be lost.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/3F/81/wKioL1PKDlXTP1XGAAIXcogI-V4345.jpg "Title =" 11.png" alt = "wKioL1PKDlXTP1XGAAIXcogI-V4345.jpg"/> in the previous step, the logical boundary is reduced, and the physical boundary is reduced below.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/3F/81/wKiom1PKDW3SCKcMAAHNn_Qj6Ms610.jpg "Title =" 12.png" alt = "wkiom1pkdw3sckcmaahnn_qj6ms610.jpg"/>

Note: you only need to provide a name when creating a volume group and a logical volume. You do not need to provide specific location information, but the logical volume is accessed or formatted after it is created, mount and so on, you must provide its specific access path.


In addition, LVM supports the snapshot volume creation function, which allows you to create a snapshot of the status of a logical volume at a certain time point to achieve backup effect, of course, it is also limited to the backup at that time point. Similar to the snapshot function in the virtual machine, it works in a similar way and implements another access path to the original logical volume, make a snapshot of the file at that time. If the data in the original volume changes, back up the unchanged data in the original volume to the snapshot volume before the modification, then, modify the corresponding data in the original volume. If the original volume is not changed, no data exists in the snapshot volume. This is why the snapshot volume is generated very quickly, the size of the snapshot volume must be reasonably defined. The size must be defined based on the size of the data that has changed during the lifecycle of the snapshot volume. That is, if the lifecycle of the snapshot volume is one day, after that, the internal data must be backed up and archived, And the snapshot volume will be deleted. During this period, the volume of the original volume's data changes is the key factor determining the snapshot volume size, make sure to define a reasonable size. Otherwise, the snapshot volume is too small and the data volume is large, which will cause the snapshot volume to crash and cannot be used for backup.

How to Create a snapshot volume:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/3F/83/wKiom1PKG9ThYOhkAAB7mq1blBs970.jpg "Title =" 15.png" alt = "wkiom1pkg9thyohkaab7mq1blbs970.jpg"/>


Delete logical volumes, Volume groups, and physical volumes.

When logical volumes, Volume groups, and physical volumes are no longer used, you can delete the corresponding volumes in this way:

# Lvremove/dev/myvg/snap-mylv; delete a snapshot volume

# Lvremove/dev/myvg/mylv; Delete the corresponding logical volume

# Lvremove myvg; delete all logical volumes in the volume group

# Vgremove myvg; delete a volume group

# Pvremove/dev/sda3/dev/sda5; Delete the corresponding physical disk.








LVM management and usage

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.