Configure LVM (logical volume management) in CentOS 6.3)

Source: Internet
Author: User
Tags oracle vm virtualbox vm virtualbox

I. Introduction

LVM is short for Logical Volume Manager. It is a mechanism for managing disk partitions in Linux, LVM is a logical layer built on hard disks and partitions to improve the flexibility of disk partition management.

The operating principle of LVM is actually very simple. It encapsulates the underlying physical hard disk abstraction and presents it to upper-layer applications in the form of logical volumes. In the traditional disk management mechanism, our upper-layer applications directly access the file system to read the underlying physical hard disk. In LVM, it encapsulates the underlying hard disk. When we operate the underlying physical hard disk, it is no longer for partitioning, instead, you can manage the underlying disk of a logical volume. For example, if I add a physical hard disk, the upper-layer service will not feel it at this time, because the upper-layer service is presented in a logical volume.

The biggest feature of LVM is its ability to dynamically manage disks. Because the logical volume size can be dynamically adjusted without losing existing data. If we add a new hard disk, it will not change the existing upper-layer logical volume. As a dynamic disk management mechanism, logical volume technology greatly improves the flexibility of disk management.

Basic logical volume management concepts:

PV (Physical Volume)-Physical Volume
The physical volume is at the bottom of the logical volume management. It can be an actual physical hard disk.Partition, Or the wholePhysical Hard Disk, Or yesRaid device.

VG (Volumne Group)-volume Group
A volume is created on top of a physical volume. A volume group must contain at least one physical volume. After a volume group is created, the physical volume can be dynamically added to the volume group. A logical volume Management System project can have only one or more volume groups.

LV (Logical Volume)-Logical Volume
The logical volume is created on the volume group. unallocated space in the volume group can be used to create new logical volumes. After the logical volume is created, the space can be dynamically expanded and reduced. Multiple logical volumes in the system can belong to the same volume group or different volume groups.

The diagram is as follows:

Ii. System Environment

Lab environment:Oracle VM VirtualBox

System Platform:CentOS release 6.3 (Final)

Mdadm version:Mdadm-v3.2.6-25th October 2012

LVM version:Lvm2-2.02.100-8.el6.i686

Device Type:Partition, physical hard disk, raid device

Iii. Disk preparation

In this article, we will simulate three types of devices: RAID 5, partitioning, and physical hard disk to create VG. RAID 5 requires four hard disks, one partition and one hard disk, there is also a need for at least one hard disk during resizing, so Add eight hard disks to the virtual machine, each of which is 5 GB.

4. Install LVM management tools

4.1 check whether LVM management tools are installed in the system

# Rpm-qa | grep lvm

4.2 if not, use yum to install

# Yum install lvm *

# Rpm-qa | grep lvm

5. Create a RAID 5 Device

Perform soft raid simulation using four physical hard disks:/dev/sdb,/dev/sdc,/dev/sdd, And/dev/sde.

# Mdadm-C/dev/md5-ayes-l5-n3-x1/dev/sd [B, c, d, e]

6. Create a partition

Use/dev/sdf to simulate partitions.

# Fdisk/dev/sdf

# Fdisk-l/dev/sdf

VII. Create a PV

# Pvcreate/dev/md5/dev/sdf1/dev/sdg

8. Create VG

# Vgcreate vg0/dev/md5/dev/sdf1/dev/sdg

9. Create LV

# Lvcreate-L 5G-n lv1 vg0

10. Format LV

# Mkfs. ext4/dev/vg0/lv1

11. Mount and use

# Mkdir/mnt/lv1

# Mount/dev/vg0/lv1/mnt/lv1/

# Df-TH

12. Add Test Data

Next we will resize and scale down the LVM, so write test data to/mnt/lv1 to verify the dynamic disk management of the LVM.

# Touch/mnt/lv1/test_lvm_dynamic.disk

# Touch/mnt/lv1/test_lvm_dynamic.disk2

# Touch/mnt/lv1/test_lvm_dynamic.disk3

# Ll/mnt/lv1/

13. LVM resizing

The biggest advantage of LVM is that it can dynamically manage Disks without losing existing data.

If one day the lv1 usage reaches 80% and needs to be expanded, what should we do?

Because vg0 still has a lot of available space, we can allocate point space from vg0 to lv1.

13.1 LV resizing

Check the remaining vg0 capacity, and 14.98 GB is available.

14. LVM reduction

The scale-down operation must be processed offline.

Reduction of 14.1 LV

A. umount File System

15. Delete LVM

If you want to completely remove the LVM, You need to reverse the creation steps.

15.1 umount File System

16. LVM snapshot (snapshot)

Snapshots are used to record the system information at that time, just like taking photos. If any data changes in the futureThe original data will be moved to the snapshot area, and the region that has not been changed will be shared by the snapshot area and the file system..

Backup of the snapshot area of the LVM system (the dotted line is the file system, and the long dotted line is the snapshot Area)

The figure on the left shows the initial creation of the System Snapshot zone. LVM reserves an area (three PE blocks on the left of the left) as the data storage location. At this time, there is no data in the snapshot zone, and the snapshot zone shares all PE data with the system zone. Therefore, you will see that the content in the snapshot zone is exactly the same as that in the file system. After the system is running for A while, if the data in area A is changed (as shown in the figure above), the system will move the data in the region to the snapshot area before the change, therefore, a pe is occupied in the snapshot area on the right to become A, while other blocks from B to I are still shared with the file system!

The Snapshot zone and the snapshot LV must be in the same VG.

16.1 create LV

# Lvcreate-L 100 M-n lv1 vg0

# Mkfs. ext4/dev/vg0/lv1

# Mount/dev/vg0/lv1/mnt/lv1/

16.2 write Test Data

# Touch/mnt/lv1/test_lvm_snapshot_1

# Touch/mnt/lv1/test_lvm_snapshot_2

# Cp-a/etc // mnt/lv1/

# Cp-a/boot // mnt/lv1/

Note:The volume of modification to lv1 cannot exceed the snapshot size. Because the raw data will be moved to the snapshot area, if your snapshot area is not large enough, if the actual data volume of the original data is larger than that of the snapshot area, the snapshot area cannot accommodate the data. At this time, the snapshot function will become invalid!

 

References

  • Laruence Linux Private food: http://linux.vbird.org/linux_basic/0420quota.php#lvm
  • Yu Fei blog: http://www.opsers.org/base/one-day-a-little-learning-linux-logical-volume-manager-lvm-on-the-rhel6.html

 

Configure Software RAID in CentOS 6.3)

Http://www.cnblogs.com/mchina/p/linux-centos-disk-array-software_raid.html

 

David Camp

  • For technical exchange, add the QQ group:

System O & M Technology: 296513821

  • For business cooperation, contact the author QQ: 562866602
  • My ID: mchina_tang
  • Write to me: mchina_tang@qq.com
  • My address: Suzhou, Jiangsu Province

We always believe that sharing is a virtue |We Believe, Great People Share Knowledge...

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.