Linux Learning--LVM

Source: Internet
Author: User

First, what is LVM?

LVM is the short name for logical volume management (Logical Volume Manager), an abstraction layer built on a physical error device that allows you to generate logical storage volumes. and direct use of physical storage provides greater flexibility than management.

LVM will store virtual sessions, use logical volumes, you will not be limited to the size of the physical disk, and hardware-related storage settings are hidden, you can not stop the application or unmount the file system to adjust the size of the volume or data migration, which can reduce operational costs.

LVM is compared to using physical storage directly:
1. Flexible capacity

When using logical volumes, the file system can be extended to multiple disks, and you can aggregate multiple disks or partitions into a single logical volume.

2. Scalable Storage Pool

You can use simple commands to enlarge or reduce the size of the logical volume without reformatting or partitioning the disk device.

3 online data in the distribution

You can move data online, and the data can be redistributed as the disk is online. For example, you can replace hot-swappable disks online.

4. Convenient naming of equipment

Logical volumes can be all names in a way that you feel convenient.

5. Disk Fragmentation

You can generate a logical disk whose data can be stored on 2 or more disks. This can significantly improve data throughput.

6. Image Volume

Logical volumes provide a convenient way to image your data.

7. Volume Snapshots

With logical volumes, you can get device snapshots that are used for consistent backup or test data update effects without impacting real data.

Ii. Basic terminology of LVM

LVM is a logical layer that is added to the physical storage to mask the underlying hardware storage device for the file system, providing an abstract disk volume that creates a file system on the disk volume.

Physical storage media (the physical media)

This refers to the system's storage devices, such as:/DEV/HDA1,/DEV/SDA, etc., is the storage system at the bottom of the storage unit.

Physical volume (pv,physical Volume)

A physical volume refers to a disk, a disk partition, or a device (RAID) that has the same functionality as a logical and disk partition, which is the basic storage logic block of LVM, but is compared with basic physical storage media (such as partitions, disks, etc.) and contains management parameters related to LVM. The current LVM allows you to save 0 to 2 copies of the metadata for this physical volume on each physical volume, with a default of 1, which is guaranteed at the beginning of the device. Buy at 2 to save the second backup at the end of the device.

Volume groups (vg,volume group)

Volume groups are the highest level of abstraction used in LVM. It sets up logical volumes and physical volumes together to become a snap-in.

Logical volumes (lv,logical Volume)

Equivalent to a disk partition in a non-LVM system. The LV is visible as a standard block device, so the LV can contain a file system (for example: Home)

Linear logical volumes (Linear Volume)

A linear logical volume aggregates multiple physical volumes into a single logical volume. For example: If you have two 60GB hard disks, you can generate 120GB of logical volumes.

A striped logical volume (striped Logical Volumes)

When you write data into this logical volume, the file system can put data into multiple physical volumes, which can improve data I/O efficiency for a large number of connection read and write operations

Logical volume of the image (mirrored Logical Volumes)

Images store consistent data on different devices. The data is written to both the original device and the imaging device. It provides fault tolerance between the devices.

Snapshot Logical Volume (Snapshot Volumes)

The snapshot volume provides a virtual image of a device at a particular moment in time, and when the snapshot begins, he is responsible for a change to the current data region, which allows him to refactor the current device state as he prioritizes the changes.

PE (physical Extent)

Physical extents: Each physical volume is divided into a basic unit called a PE (physical extents), and a uniquely numbered PE is the smallest unit that can be addressed by LVM. The size of the PE is configurable and defaults to 4MB.

LE (Logical Extent)

Logical extents: Logical volumes are divided into addressable basic units called LE (Logical extents). In the same volume group, the size of Le is the same as the PE, and one by one corresponds.

and non-LVM systems The metadata that contains the partition information is saved in the partition table at the beginning of the partition, and the metadata related to the logical volume and volume group is also stored in the Vgda (Volume Group descriptor area) at the beginning of the physical volume. Vgda includes the following: PV descriptors, VG descriptors, LV descriptors, and some PE descriptors. When the system initiates LVM, the VG is activated and the Vgda is loaded into memory to identify the actual physical storage location of the LV. When the system does an I/O operation, the mapping mechanism established by VGDA is eradicated to access the actual physical location.

Several conceptual relationships

For example:

Let's say we have a volume group called VG1, the physical size of this volume group is 4MB, and in this volume group we introduced 2 hard disk partitions/dev/hda1 and/DEV/HDB1.

These partitions will become physical volumes PV1 and PV2 (administrators can decide whether to provide more meaningful names at their discretion)

PV is divided into 4MB blocks, because this is the size of the volume group. The disk size is different, we get 99 extents in PV1, 248 extents in PV2.

We can now create our own logical volume, which can be any size between 1 and 347 (248+99) ranges.

When creating a logical volume, a mapping is defined between the logical and physical extents, for example, logical extents 1 can be mapped to the physical extents of PV1 51, and the first 4MB of data written to the logical disk is actually written to the 51st panel of the PV1.

Mapping mode

Linear Mapping: Assign a range of PE to an area of the LV, such as le1-99 mapping to pv1,le100-347 mapping to PV2.

Stripe mapping: A block that weaves the logical extents across multiple physical volumes, which improves performance to some extent, as follows:

1st chunk of Le[1]-pv1[1] # The first logical block on the PV1 device, the second logical block on the PV2 device, etc.

2nd chunk of le[1], pv2[1]

3rd chunk of le[1], pv3[1]

4th chunk of Le[1], pv1[2]

Snapshots (snapshot)

This is an excellent feature provided by LVM, which allows the administrator to create a new block device to render an exact copy of a logical volume, freeze at a certain time, and the administrator can back up the data in the specified consistent state in a timely manner, and the device can be deleted after the backup is complete.

The snapshot initially contains some metadata about the snapshot, but there is no actual data from the source logical volume. The snapshot uses write-time copy on write technology to detect when the data is changed in the original data block. It copies the values that were saved when the snapshot was taken to a block in the snapshot volume, and then allows the new data to be stored in the source block.

As more blocks change from the original value on the source logical volume, the snapshot size also increases. If the snapshot volume becomes full. It will be discarded, so allocating enough space is very important, depending on your data transformation situation, and if the snapshot size is as large as the original data, it will never overflow.

Linux Learning--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.