LVM briefing Hall

Source: Internet
Author: User

Introduction

Today, when the data volume increases daily, the server is often faced with insufficient partition space for normal use. If you still use the traditional partitioning method, add a new hard disk, then, split and format the original data, copy the original data, and then unmount the original partition and re-mount the new partition. Ah! Busy! If it is the second split, it will give too much capacity! A lot of disk capacity is wasted! What should you do when you want to narrow down the partition? The emergence of LVM is precisely to solve these problems...

LVM (full name: logical volume manager Chinese name: logical volume manager), also translated into logical File Manager, logical Sector Manager, Logical Disk Manager, it is the core logical volume management function of Linux. It creates a logic layer on top of the hard disk partition to facilitate system management of the hard disk partition system. First developed by IBM and implemented on the AIX system, the OS/2 Operating System and HP-UX also support this feature. In 1998, Heinz mauelshagen made the first Linux version of logical volume manager according to the logical volume manager on the HP-UX.

LVM allows you to adjust the size of the file system without stopping services. This allows the file system to span disks and partitions, its appearance can be said to solve many problems of disk management. Let's take a look at it so well. Let's take a look at it and learn a few terms before introducing how to use it.


Terms

1. PM: physical media)

This refers to the storage device of the system: hard disk, which is the storage unit at the lowest layer of the storage system.


2. PV: physical volume (physical volume)

A physical volume refers to a hard disk partition or a device (such as RAID) with the same functions as a disk partition logically. It is the basic storage Logical Block of LVM, however, compared with basic physical storage media (such as partitions and disks), LVM-related management parameters are included (that is, management data of LVM is attached to traditional partitions ).


3. PE :( physical extent)

Each physical volume is divided into basic units called physicalextents. pes with unique numbers are the smallest units that can be addressed by LVM. The PE size is configurable. The default value is 4 MB.


4. VG: volume group)

An LVM volume group is similar to a physical hard disk in a non-LVM system and consists of physical volumes. You can create one or more "LVM partitions" (logical volumes) on the volume group. The LVM volume group consists of one or more physical volumes.


5. LV: logical volume)

The logical volume of LVM is similar to the hard disk partition in a non-LVM system. A file system (such as/home or/usr) can be created on the logical volume ).


6. Le :( logical extent)

Logical volumes are also divided into the addressable basic units called Le (logicalextents. In the same volume group, the Le size and PE are the same and one-to-one correspondence.

 

Structure Analysis

650) This. width = 650; "Title =" maid "alt =" wkiol1pl2wqwmbfaaae8dq4_8og542.jpg "src =" http://s3.51cto.com/wyfs02/M00/3F/A7/wKioL1PL2wqwMBFaAAE8Dq4_8og542.jpg "/>

First, we can see that a physical volume (PV) is composed of an equivalent basic unit PE, and a volume group is composed of one or more physical volumes. Obviously, PE and Le have a one-to-one relationship. The logical volume is created on the volume group. A logical volume is equivalent to a non-LVM system disk partition. You can create a file system on it.


How LVM works
Let's take a look at how LVM works. Each physical volume is divided into several basic units, namely, PE. The PE size is variable, but must be the same as the physical volume of the volume group to which it belongs. In each physical volume, each PE has a unique number. PE is the smallest unit in physical storage that can be addressed by LVM.


Each logical volume is also divided into some basic units that can be addressable, that is, the so-called le. In the same volume group, the size of Le is the same as that of PE. Obviously, the size of Le is the same for all logical volumes in a volume group.


In a physical volume, each PE has a unique number, but this is not necessarily necessary for a logical volume. This is because logical volumes can be grouped by physical volumes when these pe ID numbers cannot be used. Therefore, the Le ID is used to identify the Le and its specific PE. As mentioned above, le and PE correspond one to one. Each time the storage area is accessed by addressing or the ID of the Le is used, data is written on the physical storage device.


You may wonder where all the metadata about the logical volume and logical volume group is stored. Similarly, in a non-LVM system, partition data is stored in the partition table, and the partition table is stored in the starting position of each physical volume. The vgda (volume group descriptor region) function is like a LVM partition table, which is stored at the beginning of each physical volume.


Vgda consists of the following information:
· A pv Descriptor
· A vg Descriptor
· LV Descriptor
· Some PE Descriptors


When the system starts the LV, the VG is activated and the vgda is loaded to the memory. Vgda helps identify the actual storage location of the LV. When the system wants to access the storage device, the ing mechanism established by vgda is used to access the actual physical location for I/O operations.


LVM commands

Install the LVM package before creating and using LVM.

   # rpm -qa | grep ‘lvm‘

650) This. width = 650; "Title =" qqpinyin unnamed .png "alt =" wkiol1pl30twe243aacvx_xbqus113.jpg "src =" http://s3.51cto.com/wyfs02/M01/3F/A7/wKioL1PL30TwE243AACvx_XBQus113.jpg "/>


Create View Details View Summary Delete Add Decrease
PV Pvcreate Pvdisplay PVS Pvremove

VG Vgcreate Vgdisplay Vgs Vgremove Vgexten Vgreduce
LV Lvcreate Lvdisplay LVS Lvremove Lvexten Lvreduce

As can be seen from the above table, most of the commands are similar, so it is easier to remember.


PV Usage Details

Create pvcreate device (/dev/sda1)

Delete pvremove device (/dev/sda2)


VG Usage Details

Create vgcreate vgname PV

        # vgcreate myvg /dev/sda1 /dev/sda2

Delete vgremove vgname

        # vgremove myvg

Add vgextend vgname PV

# Vgextend myvg/dev/sda2

Reduce vgreduce vgname PV


LV Usage Details

Add lvcreate-L [+] size-N name VG

# Lvcreate-l 512 M-N mylv1 myvg

Delete lvremove LV

The two types of LV are as follows:

        # lvremove /dev/myvg/mylv1

Or use

        # lvremove /dev/mapper/myvg-mylv1

Increase lvextend-L [+] size LV

# Lvextend-L 1g/dev/myvg/mylv1

Reduce lvreduce-L [-] size LV

# Lvreduce-L-256 m/dev/mapper/myvg-mylv1


Practice (create LVM)

1. First, partition a disk and mark it as an LVM disk.

# Fdisk/dev/SDB

650) This. width = 650; "Title =" lvm1.png "alt =" wKiom1PL6EyDg7fDAAGf-BfsZUs754.jpg "src =" http://s3.51cto.com/wyfs02/M02/3F/AA/wKiom1PL6EyDg7fDAAGf-BfsZUs754.jpg "/>

# T

Change to 8E

650) This. width = 650; "Title =" lvm2.png "alt =" wkiol1pl6wfge2pjaagckext7bs870.jpg "src =" http://s3.51cto.com/wyfs02/M01/3F/AA/wKioL1PL6WfgE2PjAAGCkEXt7Bs870.jpg "/>

2. Create it as PV

# Pvcreate/dev/sdb1

650) This. width = 650; "Title =" lv3.png "alt =" wkiol1pl6q6svsktaab8cm0cy9m276.jpg "src =" http://s3.51cto.com/wyfs02/M02/3F/ AB /wKioL1PL6q6SvSKTAAB8cM0cY9M276.jpg "/>

3. Create a VG and add the PV/dev/sdb1 to the VG group.

# Vgcreate myvg/dev/sdb1

650) This. width = 650; "Title =" lvm4.png "alt =" wkiom1pl6e3il6xeaacavwevzg8000.jpg "src =" http://s3.51cto.com/wyfs02/M00/3F/AA/wKiom1PL6E3iL6xeAACAvWEVZg8000.jpg "/>

4. Create a m lV in the volume group of myvg.

# Lvcreate-l 512 M-N mylv1 myvg

650) This. width = 650; "Title =" lvm5.png "alt =" wKioL1PL6WjQPsZ-AACJDE4Xp98809.jpg "src =" http://s3.51cto.com/wyfs02/M01/3F/AA/wKioL1PL6WjQPsZ-AACJDE4Xp98809.jpg "/>

5. format the logical volume mylv1 to the file system format of ext4.

# Mke2fs-T ext4/dev/myvg/mylv1

650) This. width = 650; "Title =" lvm6.png "alt =" wkiom1pl6e_q_lglaamjv1if8l8991.jpg "src =" http://s3.51cto.com/wyfs02/M00/3F/AA/wKiom1PL6E_Q_LglAAMJV1if8l8991.jpg "/>

6. Finally, Mount mylv1 to the/mnt/data directory, and you will be able to access it.

# Mount/dev/myvg/mylv1/mnt/Data

650) This. width = 650; "Title =" lvm7.png "alt =" wkiol1pl6wqwvultaajkrb_1pmy526.jpg "src =" http://s3.51cto.com/wyfs02/M02/3F/AA/wKioL1PL6WqwvUltAAJkrb_1pmY526.jpg "/>

This article is from the "LC's it path" blog. For more information, contact the author!

LVM briefing Hall

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.